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

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.
This commit is contained in:
Niels Dossche 2023-10-19 11:34:55 +01:00 committed by GitHub
parent 7d551a89e5
commit cdfa016854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -1547,7 +1547,10 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
do {
dst--;
src--;
ZVAL_COPY_OR_DUP_PROP(dst, src);
/* We don't have to account for refcounting because
* zend_declare_typed_property() disallows refcounted defaults for internal classes. */
ZEND_ASSERT(!Z_REFCOUNTED_P(src));
ZVAL_COPY_VALUE_PROP(dst, src);
if (Z_OPT_TYPE_P(dst) == IS_CONSTANT_AST) {
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
ce->ce_flags |= ZEND_ACC_HAS_AST_PROPERTIES;