Skip to content

Commit cdfa016

Browse files
authored
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.
1 parent 7d551a8 commit cdfa016

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Zend/zend_API.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,11 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
16101610
zval *end = src + class_type->default_properties_count;
16111611

16121612
if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
1613+
/* We don't have to account for refcounting because
1614+
* zend_declare_typed_property() disallows refcounted defaults for internal classes. */
16131615
do {
1614-
ZVAL_COPY_OR_DUP_PROP(dst, src);
1616+
ZEND_ASSERT(!Z_REFCOUNTED_P(src));
1617+
ZVAL_COPY_VALUE_PROP(dst, src);
16151618
src++;
16161619
dst++;
16171620
} while (src != end);

Zend/zend_inheritance.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,10 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
15471547
do {
15481548
dst--;
15491549
src--;
1550-
ZVAL_COPY_OR_DUP_PROP(dst, src);
1550+
/* We don't have to account for refcounting because
1551+
* zend_declare_typed_property() disallows refcounted defaults for internal classes. */
1552+
ZEND_ASSERT(!Z_REFCOUNTED_P(src));
1553+
ZVAL_COPY_VALUE_PROP(dst, src);
15511554
if (Z_OPT_TYPE_P(dst) == IS_CONSTANT_AST) {
15521555
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
15531556
ce->ce_flags |= ZEND_ACC_HAS_AST_PROPERTIES;

0 commit comments

Comments
 (0)