Repository navigation
Description
Bug report
As I mentioned in one thread PHPStan 1.8 seems to be lot slower on my project than version 1.4. Opening this thread to report what I find. Unfortunately since blackfire cancelled their free tier I have no way to investigate in as much detail as I'd like.
Anyway first thing I found is a test class that takes ~25 seconds to analyze. I can't post it publicly but the main issue is likely the two-dimensional associative array in it's @dataProvider function. It looks something like this:
return [
'string' => [
'key' => ValueObject::fromValues(...),
'key1' => SomeClass::constant
&& \in_array(
AnotherClass::constant,
YetAnotherClass::constant,
true,
),
'key2' => SomeClass::constant
&& \in_array(
AnotherClass::constant,
YetAnotherClass::constant,
true,
),
'key3' => SomeClass::constant
&& \in_array(
AnotherClass::constant,
YetAnotherClass::constant,
true,
),
'key4' => SomeClass::constant
&& \in_array(
AnotherClass::constant,
YetAnotherClass::constant,
true,
),
'key5' => SomeClass::constant
&& \in_array(
AnotherClass::constant,
YetAnotherClass::constant,
true,
),
],
// ... several more arrays like that
];
I can sen you the class privately if needed.
Another thing that is really slow is analysis of Doctrine entities. However in this case I assume it's because a custom rule which was loading Doctrine annotations in an inefficient way so I'm trying to optimize that first before making conclusions. See #8144
Aside from that it mostly seems to be a slowdown in general. I'd like to do a comparison of what classes took longer than on the previous version. I'll write a parser for the --debug -vvv results to make it a json instead so that I can compare what classes are taking longer now compared to the old version.
Activity
mergeable commentedon Oct 10, 2022
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
ondrejmirtes commentedon Oct 10, 2022
You can always anonymize the source code so that it doesn't contain anything proprietary.
enumag commentedon Oct 10, 2022
I tried but the anonymized code doesn't have the same problem. It seems to be heavily dependent on the values the constants resolve to somehow (mostly UUIDs but it seems the amount and whether or not they're the same or not matters a lot). I can't create a reproducible case out of this in a reasonable amount of time which means you can't really do much about it either... but yeah there is definitely some slowdown going on with large array constants so keep an eye for similar reports...
But anyway that's just one class, I still need to investigate the rest.
mmarton commentedon Oct 10, 2022
Don't want to hijack this issue, but I can confirm a serious regression in performance between v1.8.0 - v1.8.6 and v1.8.6 - v1.8.8.
that 1 file on the middle takes 90% of the time phpstan uses. The file has 13k static array data in it and some functions. (hungarian counties, cities, gps coords and some extra info. I can post it, it's public data)
the same file on phpstan 1.8.6:
and phpstan 1.8.0
my config file:
rvanvelzen commentedon Oct 10, 2022
@mmarton please provide the slow file so we can figure out what's happening.
mmarton commentedon Oct 10, 2022
I've uploaded a minimal POC: https://github.com/mmarton/phpstan-issue8146
enumag commentedon Oct 10, 2022
Hmm it seems performance is ok-ish on my side after optimizing our custom rules. So I'd actually close this issue if it wasn't hijacked 😅
SaschaHowe commentedon Oct 12, 2022
Hey,
I want to confirm @mmarton findings. The execution time for this
jumps from
to
Interestingly, just removing the 4 lines deliveryCity reduces the runtime to ~17 seconds, and removing another 4 lines for example the deliveryCity it's down to 4 seconds.
Hope this helps.
robertbasic commentedon Oct 21, 2022
Just to chime in, our static analysis job went from ~5 minutes to ~20 minutes on ~16000 files. We went from 1.4.8 to 1.8.8.
Edit: Did a few pipelines with different major versions:
Edit 2: We're using the following community extensions/custom rules, deactivating them doesn't affect the time too much, less than a minute:
mmarton commentedon Oct 25, 2022
@rvanvelzen Any news about this issue? Currently I've excluded the affected file... Let me know if I can help investigating
costash commentedon Dec 1, 2022
I've experienced a similar performance issue with versions after 1.5.7. For now I've pinned phpstan to 1.5.7 in our projects, but would be great to find the root cause of this.
staabm commentedon Dec 1, 2022
please open a separate issue with a concrete code example so we can investigate
ruudk commentedon Dec 8, 2022
For our project I investigated which files are the slowest to analyze and found a few files that contained 2000+ lines or array declarations. By refactoring a those files we were able to reduce the time with 5,5 minutes 🤯 . To make it easier to find these files for others, I published the script I used to investigate it. Maybe it can be useful for others too 😊
staabm commentedon Dec 8, 2022
if you have a reproducible test-case which is slow, please send it our way, so we can see where we can improve phpstan
mmarton commentedon Dec 8, 2022
I've already did: #8146 (comment)
ondrejmirtes commentedon Dec 11, 2022
I classified several problems from this thread and created new issues based on them:
I'm gonna close this issue because it got a bit out of hand. If you have any performance issues, please open a separate issue for each one and provide an example, so that we can either group it with other similar issues, or identify it as a new category. Thanks.
ondrejmirtes commentedon Dec 13, 2022
I'm eager to hear the time it takes to process your codebase in PHPStan 1.9.3. Please measure it and report back :) Maybe it's gonna be improved.
staabm commentedon Dec 13, 2022
one report at twitter suggests a 25% improvement
https://twitter.com/n_silbernagel/status/1602652985678503936
ruudk commentedon Dec 13, 2022
Amazing work on this:
1.9.2: 11 minutes and 5.42 seconds
1.9.3: 9 minutes and 19.90 seconds
On 14500 files.
🚀 🔥 👏 💙
rene-bos commentedon Dec 14, 2022
These performance gains are amazing!! From 7 minutes 15 seconds minute back to 5 minutes and 7 seconds! A performance gain of 28%! 💪🏻 🥳
Good job @staabm and the rest, a huge thanks form us!
ondrejmirtes commentedon Dec 14, 2022
We're not stopping here. I want to give you tools to find out the slowest files in your codebase which will be useful for further inspection. Either you'll choose to exclude them from the analysis (like we do for example with https://github.com/phpstan/phpstan-src/blob/1.9.x/resources/functionMap.php), or you'll report them in GitHub issues, so we could improve the performance :)
SaschaHowe commentedon Dec 14, 2022
Hey,
thank you very much for your efforts 🎉 👍
my test case from above today went from 86.21 seconds on 1.8.7 to 37.48s on 1.9.3 which is a huge improvement. 🎉
But it's still a big performance hit compared to 1.8.6 with its 0.19s. I'm not sure what exactly happened in 1.8.7 that caused this increase in time and memory but it feels like for a "simple" file like the one in my test, it's a bit much time.
See below the details for the runs.
enumag commentedon Dec 14, 2022
For me it went from 16 mins to 15 mins and 15 seconds. Still a good improvement. 👍
mmarton commentedon Dec 14, 2022
Form me (https://github.com/mmarton/phpstan-issue8146/blob/master/src/DataFixtures/LocationFixtures.php) it went down by ~74%
thank you for the great work
github-actions commentedon Jan 15, 2023
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.