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

Large memory consumtion when extends class #4435

Closed
fezfez opened this issue Jan 26, 2021 · 12 comments
Closed

Large memory consumtion when extends class #4435

fezfez opened this issue Jan 26, 2021 · 12 comments

Comments

@fezfez
Copy link

fezfez commented Jan 26, 2021

Bug report

Hello,

I come with another interesting case of large memory consumption when extending a class (TCPDF)

Code snippet that reproduces the problem

i made a little repository with a complete reproduction case https://github.com/fezfez/phpstan-memory

Expected output

I think class MemoryConsumptionMini and LargeMemoryConsumption should have pretty same memory usage

@mergeable
Copy link

mergeable bot commented Jan 26, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

To be fair, both of the files cause a similar memory footprint for me on 0.12.69:

phpstan-memory main $ time ./vendor/bin/phpstan analyse --debug -vvv src/LargeMemoryConsumption.php
Note: Using configuration file /Users/ondrej/Downloads/phpstan-memory/phpstan.neon.
Result cache not used because of debug mode.
/Users/ondrej/Downloads/phpstan-memory/src/LargeMemoryConsumption.php
--- consumed 222 MB, total 278 MB
Result cache was not saved because only files were passed as analysed paths.


 [OK] No errors


Used memory: 278 MB

real	0m3.062s
user	0m2.138s
sys	0m0.635s
phpstan-memory main $ time ./vendor/bin/phpstan analyse --debug -vvv src/MemoryConsumptionMini.php
Note: Using configuration file /Users/ondrej/Downloads/phpstan-memory/phpstan.neon.
Result cache not used because of debug mode.
/Users/ondrej/Downloads/phpstan-memory/src/MemoryConsumptionMini.php
--- consumed 186 MB, total 242 MB
Result cache was not saved because only files were passed as analysed paths.


 [OK] No errors


Used memory: 242 MB

real	0m1.983s
user	0m1.547s
sys	0m0.399s

@fezfez
Copy link
Author

fezfez commented Jan 26, 2021

Strange because i don't have the same output as you.

time ./vendor/bin/phpstan analyse --debug -vvv src/LargeMemoryConsumption.php
Note: Using configuration file /home/fezfez/work/phpstan-memory/phpstan.neon.
Result cache not used because of debug mode.
/home/fezfez/work/phpstan-memory/src/LargeMemoryConsumption.php
--- consumed 210 MB, total 246 MB
Result cache was not saved because only files were passed as analysed paths.

                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

Used memory: 246 MB

real	0m3,245s
user	0m2,700s
sys	0m0,448s
fezfez@fezfez-Inspiron-17-7779:~/work/phpstan-memory$ time ./vendor/bin/phpstan analyse --debug -vvv src/MemoryConsumptionMini.php
Note: Using configuration file /home/fezfez/work/phpstan-memory/phpstan.neon.
Result cache not used because of debug mode.
/home/fezfez/work/phpstan-memory/src/MemoryConsumptionMini.php
--- consumed 22 MB, total 58 MB
Result cache was not saved because only files were passed as analysed paths.

                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

Used memory: 58 MB

real	0m0,473s
user	0m0,391s
sys	0m0,054s
fezfez@fezfez-Inspiron-17-7779:~/work/phpstan-memory$ composer show | grep phpstan
phpstan/phpdoc-parser                             0.4.9     PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                                   0.12.69   PHPStan - PHP Static Analysis Tool
fezfez@fezfez-Inspiron-17-7779:~/work/phpstan-memory$ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Maybe it depend on php version ?

@fezfez
Copy link
Author

fezfez commented Jan 26, 2021

i have added a github action to see result on a more neutral env, and indeed, result are pretty same as yours.
https://github.com/fezfez/phpstan-memory/runs/1769470321?check_suite_focus=true

@fezfez
Copy link
Author

fezfez commented Jan 26, 2021

i have submit an issue to shivammathur/setup-php#402 to see if i can have a complete reproduction case

@ondrejmirtes
Copy link
Member

I did a very low-hanging fruit optimization for this case: phpstan/phpstan-src@d3435dd

It now results in 56 MB / 110 MB consumption instead :)

@ondrejmirtes
Copy link
Member

I've also seen the different consumption for each file during the development, I guess it has something to do which one you run first, how the cache is primed...

@fezfez
Copy link
Author

fezfez commented Jan 27, 2021

@ondrejmirtes nice !

With the different optimizations, this are my results on my projects (2500 files ~)

branche total memory max memory per file
dev-master 1.13 GB 56 MB
0.12.69 1.24 GB 214 MB
0.12.68 1.57 GB 338 MB

Nice work ! 👍

@ondrejmirtes
Copy link
Member

Nice :)

@ondrejmirtes
Copy link
Member

PHPStan 0.12.71 should be a bit better again performance and memory-wise, please test it and report back, thank you :)

@fezfez
Copy link
Author

fezfez commented Feb 1, 2021

With 0.12.71

Used memory: 964.97 MB
real 2m 16.40s
user 2m 14.16s
sys 0m 1.91s

with 0.12.70

Used memory: 1.15 GB
real 3m 18.39s
user 3m 11.07s
sys 0m 2.65s

minus 600 MB since 0.12.68 for me 🌈 !

@github-actions
Copy link

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 Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants