Bug #79519 [Opn]: Memory leak in PHP 7.4
Edit report at https://bugs.php.net/bug.php?id=79519&edit=1
ID: 79519
Updated by: nikic@php.net
Reported by: kieran at miami-nice dot co dot uk
Summary: Memory leak in PHP 7.4
Status: Open
Type: Bug
Package: Performance problem
Operating System: Linux
PHP Version: 7.4.5
Block user comment: N
Private report: N
New Comment:
@kieran: PHP 7.4 fixed some issues related to anonymous functions "overwriting" previous
anonymous functions in the same file under some circumstances. Unfortunately this also means that
this leak is now more pronounced, because this accidental destruction vector no longer exists.
Previous Comments:
------------------------------------------------------------------------
[2020-05-15 09:16:40] kieran at supportpal dot com
I thought it might be that too, but it seems odd that 7.4 is so much higher when that bug report
suggests the issue exists in most of 7.x
Nothing in the ms_print in my previous message?
I'll check if includes can be memorised.
------------------------------------------------------------------------
[2020-05-15 08:54:12] nikic@php.net
@kieran: The "factories" case looks like https://bugs.php.net/bug.php?id=76982, where a
file declaring an anonymous function is included many times. The anonymous function declaration will
leak in that case. This is a bug in PHP, but not one that will be fixed in 7.4. I'm not
familiar with Laravel's factory system, but it can probably be addressed there by making that
the includes are memoized.
------------------------------------------------------------------------
[2020-05-08 18:23:16] kieran at supportpal dot com
Here's the result from valgrind on the CI server (nothing to do with my reproducers). Anything
jump out Nikita? Not sure why it's blanked a lot of the lines - it's running with
--enable-debug
$ USE_ZEND_ALLOC=0 valgrind --tool=massif php vendor/phpunit/phpunit/phpunit
==25== Massif, a heap profiler
==25== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==25== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==25== Command: php vendor/phpunit/phpunit/phpunit
==25==
PHPUnit 8.5.4 by Sebastian Bergmann and contributors.
https://gist.githubusercontent.com/bytestream/ad3270993599c720eb7db8ada597eb24/raw/fe94995d1aee1eb64a9e61da07810717fb32e0da/massif.out.25
------------------------------------------------------------------------
[2020-05-05 12:07:08] jerome dot vieilledent at blackfire dot io
It seems that my profile comparisons are not easy to share, so I did some screenshots which you can
view here: https://github.com/bytestream/php74-memory-leak/issues/1
------------------------------------------------------------------------
[2020-05-05 09:25:22] jerome dot vieilledent at blackfire dot io
Hi there,
Here are 2 profiles for comparison:
- PHP 7.3.17: https://blackfire.io/profiles/b7785fda-415f-4176-a57e-f5e2417b46b0/graph
- PHP 7.4.5: https://blackfire.io/profiles/712b3b08-4ccc-4a6a-ae9b-70b4ee030334/graph
- Comparison graph:https://blackfire.io/profiles/compare/b7785fda-415f-4176-a57e-f5e2417b46b0...712b3b08-4ccc-4a6a-ae9b-70b4ee030334/graph
You have access to the timeline which shows the peak memory increasing (blue graph in the
background).
While exploring the comparison graph a bit, using the memory dimension, I found that it looks like
it's coming from explode()/implode()/array_shift():
- https://blackfire.io/profiles/compare/b7785fda-415f-4176-a57e-f5e2417b46b0...712b3b08-4ccc-4a6a-ae9b-70b4ee030334/graph?settings%5Bdimension%5D=pmu&settings%5Bdisplay%5D=focused&settings%5BtabPane%5D=nodes&selected=Faker%5CProvider%5CText%3A%3AgetConsecutiveWords%3F00a7bff87618e1493437abb5cf94878a&callname=Faker%5CProvider%5CText%3A%3AgetConsecutiveWords%3F00a7bff87618e1493437abb5cf94878a
- https://blackfire.io/profiles/compare/b7785fda-415f-4176-a57e-f5e2417b46b0...712b3b08-4ccc-4a6a-ae9b-70b4ee030334/graph?settings%5Bdimension%5D=pmu&settings%5Bdisplay%5D=focused&settings%5BtabPane%5D=nodes&selected=Faker%5CProvider%5CText%3A%3AgetExplodedText%3F00a7bff87618e1493437abb5cf94878a&callname=Faker%5CProvider%5CText%3A%3AgetExplodedText%3F00a7bff87618e1493437abb5cf94878a
I hope this helps :-)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79519
--
Edit this bug report at https://bugs.php.net/bug.php?id=79519&edit=1
Thread (25 messages)
- kieran at miami-nice dot co dot uk
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- cmb@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- kieran at miami-nice dot co dot ukBug #79519 [Com]: Memory leak in PHP 7.4
- kieran at miami-nice dot co dot ukBug #79519 [Com]: Memory leak in PHP 7.4
- kieran at miami-nice dot co dot ukBug #79519 [Com]: Memory leak in PHP 7.4
- maggus dot staab+php at gmail dot comBug #79519 [Com]: Memory leak in PHP 7.4
- cmb@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- kieran at miami-nice dot co dot ukBug #79519 [Com]: Memory leak in PHP 7.4
- jerome dot vieilledent at blackfire dot ioBug #79519 [Com]: Memory leak in PHP 7.4
- jerome dot vieilledent at blackfire dot ioBug #79519 [Com]: Memory leak in PHP 7.4
- kieran at supportpal dot comBug #79519 [Com]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- kieran at supportpal dot comBug #79519 [Com]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- kieran at supportpal dot comBug #79519 [Com]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- kieran at supportpal dot comBug #79519 [Com]: Memory leak in PHP 7.4
- kieran at supportpal dot comBug #79519 [Com]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Opn->Csd]: Memory leak in PHP 7.4
- brendt at stitcher dot ioBug #79519 [Com]: Memory leak in PHP 7.4
- nikic@php.netBug #79519 [Csd]: Memory leak in PHP 7.4
- brendt at stitcher dot ioBug #79519 [Com]: Memory leak in PHP 7.4