[php-src] Issue #9030: Performance regression when unpacking a generator yielding objects

From: Date: Sat, 16 Jul 2022 21:17:07 +0000
Subject: [php-src] Issue #9030: Performance regression when unpacking a generator yielding objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241943@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9030 Author: TRowbotham ### Description When unpacking a generator that yields objects, it takes considerably longer to unpack that generator on PHP 8.1 when compared to PHP 8.0. The regression appears to have been introduced somewhere between 8.1.0alpha2 and 8.1.0alpha3. On my machine, unpacking the generator full of objects takes roughly 85ms on PHP 7.4.24 and PHP 8.0.21, but that time increases to roughly 165ms on PHP 8.1.8. ```php <?php ini_set('memory_limit', '100M'); class Foo { private int $data; public function __construct(int $data) { $this->data = $data; } } function gen_obj(): Generator { for ($i = 0; $i < 1_000_000; ++$i) { yield new Foo($i); } } $startTime = hrtime(true); $arr = [...gen_obj()]; $endTime = hrtime(true); printf("Time taken: %.03fms\n", ($endTime - $startTime) / 1_000_000); ``` Slightly more comprehensive comparison of unpacking vs alternatives iterator_to_array and foreach, with a generator that yields integers and one that yields objects: https://gist.github.com/TRowbotham/322b29b74a07e12532d52ba331a70bd7 ### PHP Version 8.1.8 ### Operating System Ubuntu 20.04

« previous php.bugs (#241943) next »