Skip to content
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

clear-result-cache runs into out-of-memory when including big baseline #6432

Closed
j-koehler opened this issue Jan 21, 2022 · 6 comments
Closed

Comments

@j-koehler
Copy link

Bug report

Running PHPStan 1.4.2 (also occured on 1.3.3, but upgraded to check if it maybe is already fixed):

Running PHPStan through vendor/bin/phpstan clear-result-cache -c phpstan.neon runs into memory problems, when phpstan.neon includes a big baseline.

Code snippet that reproduces the problem

$ vendor/bin/phpstan clear-result-cache -c phpstan-debug.neon
PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in phar:///export/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/neon/src/Neon/Lexer.php on line 43
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in phar:///export/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/neon/src/Neon/Lexer.php on line 43

Expected output

I run analyse with --memory-limit so it's not an issue there, but clear-result-cache does not support this parameter.

I don't understand why it's relevant to load the baseline, when I just want to clear the result cache? No matter how big the base line is - result cache should be cleared. Only relevant setting processed should be the tmpDir configuration.

A workaround could be supporting --memory-limit for clear-result-cache as well?

@ondrejmirtes
Copy link
Member

Hi, how big is your baseline file? I've never seen Neon to consume so much memory!

I've added the option: phpstan/phpstan-src@156700b

@j-koehler
Copy link
Author

how big is your baseline file?

9.5mb 🙈

I've added the option: phpstan/phpstan-src@156700b

Thank you very much! 🙏

@staabm
Copy link
Contributor

staabm commented Jan 28, 2022

@mw-jko could you create a blackfire or similar profile so we can see where all the memory is consumed with such a big baseline?

Maybe there is some low hanging fruit to optimize for memory in this case...

@j-koehler
Copy link
Author

@staabm (I made the "business" github account my personal one, thus the handle change)

I will try, have no experience with blackfire (or services like this) so far.

But what I wonder is, why the clear-result-cache is even loading the baseline. I mean, in the end (ResultCacheClearer) it's just an unlink (as expected).

After getting some insight into the source code while fiddling around with the other issue this weekend my guess is, it's because of the centralized CommandHelper. Maybe this is already the room for improvement? Allowing to set the memory limit did help but the real issue is a different one.

Just not sure if it is important enough to change or how easy to change this part is.

@ondrejmirtes
Copy link
Member

I don’t think it’s worth changing it. You’ll load the baseline often anyway, so it doesn’t matter you need to wait when clearing the result cache. Which shouldn’t be normally needed anyway - if you find the need to clear it often, that’s likely a bug to be opened about that.

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants