-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
Code with looping over larger arrays from constants causes rector to be stuck while memory usage is increasing unusually high #8457
Comments
For large files, try reduce job size, eg: withParallel(120, 16, 5); so per process will only process 5 files instead of 16. |
@samsonasik thanks for the tip but this doesn't really apply in this case seeing that this problem happens when explicitly scanning a single file (see attached code from main post). |
Ok, it seems there is infinite loop on big arrays even on single rule https://getrector.com/demo/3f285eac-fd7d-45f6-8f0a-1dcb523039f2 I will take a look. |
The issue seems only on constant class, not on property on class constant (error): https://getrector.com/demo/3f285eac-fd7d-45f6-8f0a-1dcb523039f2 |
@Vaalyn the issue probably on phpstan itself, try it on https://phpstan.org/try and it got error while on property, it executed. |
I reported an PHPStan issue for it phpstan/phpstan#10538 as it infinite loop there itself. |
While wait for fix on PHPStan side, you can temporary skip the file as Rector rely on PHPStan for this ;) |
I am closing it as the issue is on phpstan itself, and already reported there While wait for fix on PHPStan side, you can do:
|
Resolved at phpstan side phpstan/phpstan-src@51cffd4 |
Bug Report
While trying to run Rector on a code base of a client to upgrade it from PHP 8.1 to 8.2 via
->withPhpSets(php82: true)
I've noticed that it get's stuck at ~95% of ~550 files while having ever increasing memory usage. I've let it run for quite some time and saw it reach over 40GB of memory used.I've then started to reduce the set of files it's running on until I landed on a single migration file of the project.
This file contains 2 constants, one of which contains an array with sub arrays, representing a change set that the static methods of the migration iterate through to build up some queries, nothing complicated.
I've then taken the migration files code and slimmed it down to just the 2 constants and one static method. Then I slimmed the method down further to just loop over the arrays & doing an
echo sprintf(...)
with the data. This slimmed down version is still causing the problematic behaviour in Rector.When I reduce the size of the larger constant it stops happening. Also when I remove
static
from the method and change theprotected const CHANGESET
into a normal class property like thisprotected array $CHANGESET
it runs pretty much instantly through the file. When I only remove thestatic
from the method but keep theCHANGESET
a constant it still runs infinitely while ballooning the memory usage.This problem seems to be somehow caused by the large/complex array constant.
Minimal PHP Code Causing Issue
The demo application is limited to 100 lines of code so I had to minify the
protected const CHANGESET
array. I'll put the correctly formatted version below: https://getrector.com/demo/23c904fb-f981-4b0d-984f-b1f8e6080d99Full Code
Expected Behaviour
I'd expect Rector to be able to process this code without getting stuck & without ever increasing memory usage.
The text was updated successfully, but these errors were encountered: