[php-src] PR #23946: ext/spl: Use fast ZPP in hot ArrayObject and ArrayIterator methods
| From: | nicolas-grekas | Date: | Sun, 27 Sep 2026 15:19:49 +0000 |
| Subject: | [php-src] PR #23946: ext/spl: Use fast ZPP in hot ArrayObject and ArrayIterator methods | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38857@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23946
Author: nicolas-grekas
return new \ArrayIterator($this->items); is the usual getIterator() implementation
of Twig nodes, Symfony bags or Doctrine collections, and profiling a foreach over such objects shows
zend_parse_parameters() taking about 180 instructions per ArrayIterator::__construct() call. This
switches both constructors and the ArrayAccess methods (offsetExists(), offsetGet(), offsetSet(),
offsetUnset(), append()) to fast ZPP. Accepted types, error messages and deprecations don't
change, and the added test pins the ones no test covered yet.
Instructions per operation (callgrind, -O2 build, arrays of 0/5/100 elements): new ArrayIterator()
-181, i.e. -16.5%/-13.8%/-6.6%, and -11.4%/-4.7%/-0.4% when followed by foreach. new ArrayObject()
-199, i.e. -17.8%/-14.9%/-7.2%, and -8.7%/-4.2%/-0.4% with foreach. offsetGet() and friends called
as methods, e.g. via parent::offsetSet() in subclasses, are 39% to 43% cheaper. Walking Twig's
node trees with foreach (17.6k nodes): -4.2% per round. The binary grows by 472 bytes of text.
It's a sibling of #23945, which removes the array duplication that dominates the 100 elements
case. Both touch spl_array.c and merge without conflict.