-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Remove most ref mismatches to improve perf #18224
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
Conversation
df9df89
to
ea33a2b
Compare
do you have a profiling comparison of the gain to know how much difference it makes ? |
// Save creating references when doing read-only lookups | ||
} elseif (is_array($zval[self::VALUE])) { | ||
$result[self::REF] = &$zval[self::REF][$index]; | ||
} elseif (is_object($result[self::VALUE])) { | ||
// Objects are always passed around by reference |
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 comment is not accurate (but we don't need a reference when dealing with objects). I suggest updating it to avoid confusing people reading the code
2fceaef
to
0c8e7ed
Compare
Here is a first comparison: $var = range(1, 1000000);
$pa = new PropertyAccessor();
$res = $pa->getValue($var, '[12]'); |
A more realistic benchmark would be to use |
0c8e7ed
to
72940d7
Compare
And one with setValue: $var = range(1, 100000);
$pa = new PropertyAccessor();
$res = $pa->setValue($var, '[12]', $var); |
These numbers are very impressive. @nicolas-grekas can you also post a benchmark for a deeper property path ? 👍 |
Thank you @nicolas-grekas. |
…f (nicolas-grekas) This PR was merged into the 2.3 branch. Discussion ---------- [PropertyAccess] Remove most ref mismatches to improve perf | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | - | License | MIT | Doc PR | - This PR is for PHP5 where ref mismatches is a perf pain: it removes all ref mismatches along the "getValue" path, and keeps only the required ones on the "setValue" path. Commits ------- 72940d7 [PropertyAccess] Remove most ref mismatches to improve perf
Awesome, thanks @nicolas-grekas :) |
This PR is for PHP5 where ref mismatches is a perf pain: it removes all ref mismatches along the "getValue" path, and keeps only the required ones on the "setValue" path.