Skip to content

Added ZEND_ASSIGN_OBJ fast path for the first write to an uninitializ… - #25057

Draft
adapik wants to merge 1 commit into
php:masterfrom
adapik:opt-assign-obj-uninit-typed-prop-master
Draft

adapik wants to merge 1 commit into
php:masterfrom
adapik:opt-assign-obj-uninit-typed-prop-master

Conversation

@adapik

@adapik adapik commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Modern PHP code mostly initializes properties through constructor property promotion, often with readonly (DTOs, value objects, services). Every such property is a typed property without a default, so its first write always goes through zend_std_write_property().

This PR adds a fast path in ZEND_ASSIGN_OBJ for the case where the cache slot is hit, the property is IS_UNDEF with IS_PROP_UNINIT set (never unset()), and neither the property nor the object is lazy. A new zend_assign_to_uninit_typed_prop() verifies the type and stores the value.

Results (release build, callgrind over 200k constructor calls with promoted readonly properties):

  • Without opcache: −24% instructions, −25% time.
  • Opcache without JIT: −24% instructions, −26% time.

Two new tests cover coercion, union and class types, readonly, protected(set), hooks and lazy objects.

This PR is related to #24566 and relies on it: that fix makes sure a failed write doesn't leave the cache slot primed. Without it, this fast path would also let a first write bypass those checks. It would be best if this lands after #24566.

Follow-up to #22709.

@adapik

adapik commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Tests will be green after #24566 lands, i put this PR to draft, but it's ready for the review. I'll rebase later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant