-
Notifications
You must be signed in to change notification settings - Fork 460
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
Reduce memory consumption of TypeInferenceTestCase #2644
Conversation
The time makes me suspicious about this change and the benchmark. |
The results are similar to the ones sugggested in the initial report of phpstan/phpstan#9914 The blackfire profiles of the report also show a 99% cost of data serialization |
I did more in detail work and found the reason/circumstances when this patch shines: phpstan/phpstan#9914 (reply in thread) only when tests are written with global code which gets executed this improvement is necessary. |
Please push your branch with the modified test code (move asserts into closures) so that I can see for myself. |
see https://github.com/staabm/phpstan-typeinferencetest-memory-exhausted/tree/closures via enabling this line, you can "enable" the change of this PR I removed a few test files of the origin repro because it was too massive slow to work with |
reproducer of the initial reported problem within the PHPStan codebase itself: #2647 in the repro we can also see that the fix of this PR here fixes the problem in phpunit10 |
I think we can close this, the root issue was addressed in PHPUnit. |
agree. upstream fix was in sebastianbergmann/phpunit#5524 |
@gnutix on my laptop I can reproduce that https://github.com/staabm/phpstan-typeinferencetest-memory-exhausted/tree/main makes phpunit slow and hang, while https://github.com/staabm/phpstan-typeinferencetest-memory-exhausted/tree/closures - where I have wrapped the tests in closures - finishes nearly instant using
|
ohh hold on a second. I just realized my |
I just force-pushed a new revision into the main branch
closure branch: (only 7 of the 31 tests have been wrapped)
there still is a big difference, but not as big as I initially reported |
OK, that's aligned with what I get locally. For now, I can't use the data providers in my TypeInferenceTest, as I can't yet upgrade to PHPUnit 10.4.x yet (it's still a dev branch, and some dependencies are not yet compatible with it). Even with sebastian/exporter 5.1.1 (sprintf fix), using
So I guess I need to wait for PHPUnit 10.4 to be released and its dependencies to be ready, and then I'll be able to add the data providers again. |
if not too much work, you might be happy with phpunit9 until then |
or alternativly you use #2644 in the meantime |
I just upgraded everything to PHPUnit 10, so thanks but no thanks! 😆
Not sure how I can do that, as PHPStan comes as a PHAR and all. 🤷♂️ No biggie, I don't really mind not having the data provider for a few weeks/months. |
in my tests I just put the but if you can live without it - thats the easiest thing to stay |
reduce the data beeing transfered between dataProvider and tests, by using just scalar values instead of objects with complex graphs which needs a lot of memory/time to serialize.
refs phpstan/phpstan#9914
repro https://github.com/gnutix/phpstan-typeinferencetest-memory-exhausted
before this PR
after this PR
=> ~98% memory improvement