Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slow analysis on big literal array #7901

Closed
staabm opened this issue Sep 2, 2022 · 4 comments
Closed

slow analysis on big literal array #7901

staabm opened this issue Sep 2, 2022 · 4 comments

Comments

@staabm
Copy link
Contributor

staabm commented Sep 2, 2022

Bug report

for some reason, we have a source file in the app which contains an array with ~90.000 literal strings.
analyzing this files takes phpstan a big amount of time:

MailAddressList.php
--- consumed 430 MB, total 766 MB, took 194.68 s

Code snippet that reproduces the problem

simplified example, which takes ~1 second to analyze:
https://phpstan.org/r/a1ac48b5-11ac-4f53-b928-2f08bc54affe
it seems my initial sample is a bit too small, because it was cut down by some tool involved.
here is a full script: https://gist.github.com/staabm/ea8b72c50c68648d48820bb7823e98b2

Expected output

faster analysis

@staabm
Copy link
Contributor Author

staabm commented Sep 2, 2022

looking at a profile suggests, that the path to generalize the literal array is already slow, because too many elements involved to build the generalized key/value types

https://github.com/phpstan/phpstan-src/blob/d37f51dabb5de6d26a5886236e726c0ad6407678/src/Type/Constant/ConstantArrayTypeBuilder.php#L270-L277

grafik

https://blackfire.io/profiles/c96451ef-d390-451b-89ed-41189665c8c0/graph

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@0cc87f3

@staabm
Copy link
Contributor Author

staabm commented Sep 3, 2022

my real world use-case with ~90.000 literal array values still takes 3-4 minutes using the latest dev-1.8. not sure this is worth investigating though.

@github-actions
Copy link

github-actions bot commented Oct 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants