Commit 41ecd7c
authored
ext/spl: Use fast ZPP in hot ArrayObject and ArrayIterator methods (#23946)
`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.
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.1 parent 62e2f86 commit 41ecd7c
1 file changed
Lines changed: 27 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
647 | | - | |
648 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | | - | |
657 | | - | |
658 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
670 | | - | |
671 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
672 | 673 | | |
673 | 674 | | |
674 | 675 | | |
| |||
689 | 690 | | |
690 | 691 | | |
691 | 692 | | |
692 | | - | |
693 | | - | |
694 | | - | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
695 | 696 | | |
696 | 697 | | |
697 | 698 | | |
698 | 699 | | |
699 | 700 | | |
700 | 701 | | |
701 | 702 | | |
702 | | - | |
703 | | - | |
704 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
| |||
1000 | 1001 | | |
1001 | 1002 | | |
1002 | 1003 | | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
1006 | 1010 | | |
1007 | 1011 | | |
1008 | 1012 | | |
| |||
1669 | 1673 | | |
1670 | 1674 | | |
1671 | 1675 | | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
1675 | 1681 | | |
1676 | 1682 | | |
1677 | 1683 | | |
| |||
0 commit comments