-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use new ZPP and inline caches in ReflectionProperty::getValue() and variants #17698
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
Use new ZPP and inline caches in ReflectionProperty::getValue() and variants #17698
Conversation
Related to #16329. |
…ized(), ::setValue(), ::setRawValue() - Pass a cache slot to the property handler - Inline the simple case of fetching a declared property - Use the new parameter parsing API This makes these methods 12% to 60% faster. Using the new parameter parsing API had the most impact, by far.
cf16078
to
a9d99e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cool
ext/reflection/php_reflection.c
Outdated
|
||
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { | ||
zval *retval = OBJ_PROP(Z_OBJ_P(object), prop_offset); | ||
if (EXPECTED(Z_TYPE_INFO_P(retval) != IS_UNDEF)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it actually matters, but I'm curious why you didn't just do Z_ISUNDEF_P
and instead go through the type info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of the happy path of ZEND_FETCH_OBJ_R
here:
Lines 2073 to 2076 in 3967b7a
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { | |
ZEND_VM_C_LABEL(fetch_obj_r_simple): | |
retval = OBJ_PROP(zobj, prop_offset); | |
if (EXPECTED(Z_TYPE_INFO_P(retval) != IS_UNDEF)) { |
I think the original code uses Z_TYPE_INFO_P()
rather than Z_TYPE_P()
/Z_ISUNDEF_P()
because type_info
is accessed again just after. Here it's not the case, and Z_TYPE_INFO_P() != IS_UNDEF
generates similar code as !Z_ISUNDEF_P()
, so I could switch to Z_ISUNDEF_P()
.
Apply the following changes to
ReflectionProperty::getValue()
,::getRawValue()
,::isInitialized()
,::setValue()
,::setRawValue()
:This results in run time decrease of 12% to 59% in micro benchmarks, when executed with
hyperfine -L version base,opt "/tmp/{version}/sapi/cli/php -d opcache.enable_cli=1 $script"
:And a 1.8% decrease in this Doctrine benchmark: arnaud-lb/symfony-demo@5058252...reflection-property-get-value-opt