Skip to content

Speed up deepclone_from_array() - #65

Merged
nicolas-grekas merged 1 commit into
mainfrom
from-array-perf
Oct 14, 2026
Merged

nicolas-grekas merged 1 commit into
mainfrom
from-array-perf

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member

Ideas from symfony/polyfill#716, plus the ones profiling showed.

On the 57 cached payloads of https://github.com/nicolas-grekas/symfony-showcase (Doctrine metadata, serializer, validator, property info and object mapper), deepclone_from_array() needs 14% fewer instructions. On a graph of 1600 objects, it needs 18% fewer.

  • Typed properties are written right after checking their type, instead of going through zend_std_write_property(), which looks them up again. This applies when the slot contains no reference, no __set() applies and a readonly property isn't initialized yet. The type is checked like before, in coercive mode.
  • Object ids, the most common marker, are resolved inline. A property of the stdClass scope is looked up once per class instead of once per object.
  • Without allow_named_closures, the payload is scanned for closures once instead of twice. The scans skip scalar markers.

The results are the same before and after on 11,000 fuzzed payloads.

@nicolas-grekas
nicolas-grekas merged commit 20290bc into main Oct 14, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant