[php-src] Issue #15105: Memory issues yield vs yield from

From: Date: Thu, 25 Jul 2024 11:03:13 +0000
Subject: [php-src] Issue #15105: Memory issues yield vs yield from
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247372@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15105 Author: mystiksong ### Description The following code: ```php <?php function some() { for ($i = 0; $i < 100000; $i++) { yield $i; } } iterator_to_array(some()); echo memory_get_usage(true) / 1024 / 1024; echo PHP_EOL; echo memory_get_peak_usage(true) / 1024 / 1024; ``` I expect to have no difference in memory usage with code bellow ```php <?php function some() { for ($i = 0; $i < 100000; $i++) { yield from [$i]; } } iterator_to_array(some()); echo memory_get_usage(true) / 1024 / 1024; echo PHP_EOL; echo memory_get_peak_usage(true) / 1024 / 1024; ``` But fragment with yield resulted in this output: Result for 8.0.30, 7.4.33, 8.1.25: ``` 2 8.0078125 ``` Result for 8.3.9, 8.2.21: ``` 2 4.00390625 ``` With increasing memory peak usage depending on action, while fragment with yield from remains stable on all described versions. I expected fragment with yield to be working same as fragment with yield from in terms of memory usage: ### PHP Version PHP 7.4.33 ,8.0.30, 8.1.25, 8.2.21, 8.3.9 ### Operating System Ubuntu 20.04.6 LTS

« previous php.bugs (#247372) next »