Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid refcounted copy in _object_properties_init() for internal classes #12474

Merged
merged 2 commits into from Oct 19, 2023

Conversation

nielsdos
Copy link
Member

This currently uses ZVAL_COPY_OR_DUP, which copies the value and handles refcounting. However, internal classes cannot have refcounted default properties because of constraints imposed by
zend_declare_typed_property(). So copying the value is sufficient.

While this doesn't really improve the performance for our benchmarks, it improves performance for cases where a lot of temporary internal objects are instantiated. For example, when instantiating DOM classes: DOM objects are transient, so lots of temporary objects are created.

I have a variant on my fork that adds a CE flag to extend this to user classes too (nielsdos#55). But the performance win is so small that I'm not convinced that's useful.

This currently uses ZVAL_COPY_OR_DUP, which copies the value and handles
refcounting. However, internal classes cannot have refcounted default
properties because of constraints imposed by
zend_declare_typed_property(). So copying the value is sufficient.

While this doesn't really improve the performance for our benchmarks, it
improves performance for cases where a lot of temporary internal objects
are instantiated. For example, when instantiating DOM classes: DOM
objects are transient, so lots of temporary objects are created.
@iluuu1994
Copy link
Member

There's similar code in zend_do_inheritance_ex, where ZVAL_COPY_OR_DUP_PROP is used. It doesn't matter much there since it's only done once per class, but to avoid confusion the same changes should probably be made there.

@nielsdos nielsdos merged commit cdfa016 into php:master Oct 19, 2023
7 checks passed
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.

None yet

3 participants