Skip to content

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

Merged
merged 3 commits into from
Feb 17, 2025

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Feb 4, 2025

Apply the following changes to ReflectionProperty::getValue(), ::getRawValue(), ::isInitialized(), ::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 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":

get-raw-value.php:   -58%
get-value-dyn.php:   -50%
get-value-hook.php:  -47%
get-value.php:       -59%
is-initialized.php:  -59%
set-value.php:       -11%

And a 1.8% decrease in this Doctrine benchmark: arnaud-lb/symfony-demo@5058252...reflection-property-get-value-opt

@TimWolla
Copy link
Member

TimWolla commented Feb 5, 2025

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.
@arnaud-lb arnaud-lb force-pushed the reflection-property-get-value-opt branch from cf16078 to a9d99e5 Compare February 11, 2025 11:39
@arnaud-lb arnaud-lb marked this pull request as ready for review February 11, 2025 14:53
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool


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)) {
Copy link
Member

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

Copy link
Member Author

@arnaud-lb arnaud-lb Feb 17, 2025

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:

php-src/Zend/zend_vm_def.h

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().

@arnaud-lb arnaud-lb merged commit 8af9042 into php:master Feb 17, 2025
9 checks passed
arnaud-lb added a commit that referenced this pull request Feb 19, 2025
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.

3 participants