-
-
Notifications
You must be signed in to change notification settings - Fork 884
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
Performance problem - nested loops #8503
Labels
Comments
This was referenced Dec 11, 2022
copying here, from #8353 (comment), a repro link: https://phpstan.org/r/03cef78d-271b-46d6-9d3a-d585fdb58c8f (the response time is ~4 seconds, when 1 more level is added, it crashes (time needed is exponential)) |
ondrejmirtes
added a commit
to phpstan/phpstan-src
that referenced
this issue
Dec 13, 2022
Closes phpstan/phpstan#6265 Closes phpstan/phpstan#8503
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Feature request
PHPStan can be really slow when analysing code like this:
PHPStan analyses different PHP loops a similar way: Go through the loop, observe if the scope changes, “generalize” the scope. If the scope is different than the last time, re-run the same process up until 3 times. Use the final scope and run the analysis with the rules etc.
The generalization is a bit hazy, basically I’m trying to write some code that compares types and tries to figure out if the loop does
$i++
vs.$i = 5
, to see what the type should be in the final scope.The problem is that my algorithm (here’s the foreach loop logic: https://github.com/phpstan/phpstan-src/blob/3c3b17f238d1ec085f74aee320e9dd321d1258d8/src/Analyser/NodeScopeResolver.php#L823-L846) is very ineffective with multiple nested loops
The more the loop is nested, the more times it’s going to be analysed. If I put
var_dump($stmt->getLine());
at the beginning of the foreach handler in NodeScopeResolver, the output when analysing the linked file looks like this:And goes on like that for more than 3,000 times.
I'd like to know how compilers of different languages handle this effectively...
The text was updated successfully, but these errors were encountered: