You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not for sure where this should go, or if anything can be done, but I figured I'd ask anyway.
We updated from 1.4.10 to 1.9.2.
Full scans of our project jumped from around 11 minutes to just over 2 hours.
After purging the cache and waiting for a full scan to complete, subsequent scans finished in about 4 seconds.
Changing a few files results in a 3-4 minute scan time, which seems great compared to the previous 11 minute scan time.
Updating a library, changing a core class, or updating modeling causes an entire 2 hour scan again.
Is there anything I can do to improve this process besides rolling back to an earlier version? I've tried running with --debug but nothing really stands out there as to what could be the issue.
Code snippet that reproduces the problem
Not applicable, but here's a link just in case the bot is too willing to auto-close
Hi, something definitely needs to show up when running with --debug. My guess is that between 1.4.10 and 1.9.2, analysis of some files will take similar time, and some will be much longer, helping us to pinpoint the reason. It can boil down to a single class with some weird code that halts the analysis.
Also, there are many changes between 1.4.10 and 1.9.2. If you run PHPStan on multiple releases and figure out where it slowed down, would also be helpful. You shouldn't do this manually, for example GitHub Actions make this very easy. Just set up the matrix with installing different PHPStan versions and you should see the results very quickly.
It looks like this started in 1.6.0. 1.5.0-1.5.7 all took 35-40 minutes. I'm only able to run a few in parallel, but 1.6.0-1.6.7 are all at 90+ minutes and are still running. I'll follow up when everything completes with a time table.
How big is the codebase? The usual benchmark I have with two big codebases is that for around 1 million lines of code in ~10k files, it takes 2-3 minutes to analyze from scratch.
Anyway, we need to nail this down to a specific cause, I still think that a few select files alone will be the cause of this huge performance hit.
I just ran vendor/bin/phpstan analyse -l 6 -c phpstan_local.neon src --debug, which finished with [OK] No Errors. It took an hour and a half, but is on better hardware.
How do you determine the time per file short of actively watching? When I run with --debug, it just lists every file individually until it reaches the end of the scan.
Thanks! It's still running, but it looks like it's an issue with large arrays. Currently, the longest individual file is 73s, and it uses a 4 dimension array. Second that up by a handful of files all in the 20-30s range that use large arrays from the DB. These are all either classes that handle large reports, or handle user submitted CSV files of data to import.
I'm fairly certain that this is dealing with arrays. 4 files took over 30s to process, all of them deal with large arrays.
73.2s file reads a CSV file that contains sensitive data , has a 4d associative array, but does not check user permissions as it's a cli routine.
51.2s file has a multiple associative arrays, no nesting, but does multiple loops over those sets of arrays based on user permissions.
38.15s file is another CSV ingest process that's basically a stripped down version of the longest running file, but is user side and has permission checks.
34.54s file has a single associative array that is constructed from numerous permission checks then cached.
Everything in the 10s-29.99s range are larger arrays that do permission checks.
I'd have assumed it was an issue with our permission system if it wasn't for the longest file. It very may well be so, due to how our permission matrix can be quite deep based on user control settings.
Is there a way to tell PHPStan to not analyze a particular function? Basically, we have a $cUser->permissionCheckBool('permission.node.here') method that's used in every case but the longest. Nearly every file over 5s uses permission checks, some only calling it a single time, but all do use some form of array or iterator.
The permission check routine explodes on period, then traverses an array checking for matching nodes. Something like admin.members.student.view would look for $permissions['admin']['members']['student']['view'] for example.
If it's an issue in the permission system, it'd definitely explain why so many take so long. After parsing the results, I came up with the following quick counts.
it seems related but different array issue - please reproduce using https://phpstan.org/try with an example that is fast enough to pass the sandpit but slow enough to not timeout - such test can be then used to devel the fix and once fixed, it can be extended to cover the original huge file/processing time
Spent a day rolling brand new Ubuntu 20.04 servers with PHP 8.1.12 to test. It's taking about the same amount of time, but I wind up with a few Internal error: Internal error: preg_match(): Argument #2 ($subject) must be of type string, array given errors in the logs. Running locally, I don't get those at all. I don't think it's related to the issue, since the files that the prior error message is appearing on are particularly small and ancient files. No idea if this is helpful at all.
Activity
ondrejmirtes commentedon Nov 11, 2022
Hi, something definitely needs to show up when running with
--debug. My guess is that between 1.4.10 and 1.9.2, analysis of some files will take similar time, and some will be much longer, helping us to pinpoint the reason. It can boil down to a single class with some weird code that halts the analysis.Also, there are many changes between 1.4.10 and 1.9.2. If you run PHPStan on multiple releases and figure out where it slowed down, would also be helpful. You shouldn't do this manually, for example GitHub Actions make this very easy. Just set up the matrix with installing different PHPStan versions and you should see the results very quickly.
ondrejmirtes commentedon Nov 11, 2022
You can also check out the existing issues labeled "performance" to see if it's a similar pattern: performance
GameCharmer commentedon Nov 11, 2022
It looks like this started in 1.6.0. 1.5.0-1.5.7 all took 35-40 minutes. I'm only able to run a few in parallel, but 1.6.0-1.6.7 are all at 90+ minutes and are still running. I'll follow up when everything completes with a time table.
GameCharmer commentedon Nov 12, 2022
Average over 3 runs each. 1.8.3 timed out after 3hrs each time. Time shot up at 1.6.0, and again at 1.7.0.
ondrejmirtes commentedon Nov 12, 2022
How big is the codebase? The usual benchmark I have with two big codebases is that for around 1 million lines of code in ~10k files, it takes 2-3 minutes to analyze from scratch.
Anyway, we need to nail this down to a specific cause, I still think that a few select files alone will be the cause of this huge performance hit.
GameCharmer commentedon Nov 12, 2022
3665 files, 733944 lines of code.
I just ran
vendor/bin/phpstan analyse -l 6 -c phpstan_local.neon src --debug, which finished with [OK] No Errors. It took an hour and a half, but is on better hardware.ondrejmirtes commentedon Nov 12, 2022
That's really a long time. I guess there's something wrong happening in the project because that's not normal.
You should parse the
--debugoutput and sort files by the time they take. I guess there is going to be some abnormalities.GameCharmer commentedon Nov 12, 2022
How do you determine the time per file short of actively watching? When I run with
--debug, it just lists every file individually until it reaches the end of the scan.ondrejmirtes commentedon Nov 13, 2022
Try
--debug -vvv.GameCharmer commentedon Nov 13, 2022
Thanks! It's still running, but it looks like it's an issue with large arrays. Currently, the longest individual file is 73s, and it uses a 4 dimension array. Second that up by a handful of files all in the 20-30s range that use large arrays from the DB. These are all either classes that handle large reports, or handle user submitted CSV files of data to import.
Will follow up post-completion.
GameCharmer commentedon Nov 13, 2022
I'm fairly certain that this is dealing with arrays. 4 files took over 30s to process, all of them deal with large arrays.
Everything in the 10s-29.99s range are larger arrays that do permission checks.
I'd have assumed it was an issue with our permission system if it wasn't for the longest file. It very may well be so, due to how our permission matrix can be quite deep based on user control settings.
Is there a way to tell PHPStan to not analyze a particular function? Basically, we have a
$cUser->permissionCheckBool('permission.node.here')method that's used in every case but the longest. Nearly every file over 5s uses permission checks, some only calling it a single time, but all do use some form of array or iterator.The permission check routine explodes on period, then traverses an array checking for matching nodes. Something like
admin.members.student.viewwould look for$permissions['admin']['members']['student']['view']for example.If it's an issue in the permission system, it'd definitely explain why so many take so long. After parsing the results, I came up with the following quick counts.
mvorisek commentedon Nov 14, 2022
if the problem is long parsing time of a large array declaration, it is duplicate of #7955
GameCharmer commentedon Nov 14, 2022
@mvorisek The arrays are constructed from query results as opposed being predefined in this case. Something like this example.
mvorisek commentedon Nov 14, 2022
it seems related but different array issue - please reproduce using https://phpstan.org/try with an example that is fast enough to pass the sandpit but slow enough to not timeout - such test can be then used to devel the fix and once fixed, it can be extended to cover the original huge file/processing time
GameCharmer commentedon Nov 17, 2022
@mvorisek I think I was able to successfully replicate something taking a long time without taking a long time.
https://phpstan.org/r/2435942d-fce5-433b-9622-a73d107d2334
The response time is just over 2.3s
mvorisek commentedon Nov 17, 2022
The avg. sandpit response time is ~2 seconds, but your demo is working, I (simplified the demo and) added a few more levels:
https://phpstan.org/r/03cef78d-271b-46d6-9d3a-d585fdb58c8f
and the response time is ~4 seconds then. When I add 1 more level, it crashes (time needed is exponential).
GameCharmer commentedon Nov 17, 2022
Thanks @mvorisek !
GameCharmer commentedon Nov 19, 2022
Spent a day rolling brand new Ubuntu 20.04 servers with PHP 8.1.12 to test. It's taking about the same amount of time, but I wind up with a few
Internal error: Internal error: preg_match(): Argument #2 ($subject) must be of type string, array givenerrors in the logs. Running locally, I don't get those at all. I don't think it's related to the issue, since the files that the prior error message is appearing on are particularly small and ancient files. No idea if this is helpful at all.ondrejmirtes commentedon Nov 22, 2022
@GameCharmer please open a separate issue about that and make sure to add a stack trace.
ondrejmirtes commentedon Dec 11, 2022
I described this category of a performance problem in a general way and opened a new issue about it: #8503
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.
GameCharmer commentedon Dec 13, 2022
Completed in just a hair over an hour. Well over a 50% reduction in processing time! :D
github-actions commentedon Jan 14, 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.