Skip to content

[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

Merged
merged 1 commit into from
Mar 21, 2016

Conversation

nicolas-grekas
Copy link
Member

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.

@stof
Copy link
Member

stof commented Mar 18, 2016

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

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

@nicolas-grekas nicolas-grekas force-pushed the fix-ref-mismatch branch 4 times, most recently from 2fceaef to 0c8e7ed Compare March 18, 2016 12:48
@nicolas-grekas
Copy link
Member Author

Here is a first comparison:
https://blackfire.io/profiles/compare/c77e869c-a5ba-44da-8cea-8a45c3c151ab/graph
capture du 2016-03-18 15 10 41

$var = range(1, 1000000);
$pa = new PropertyAccessor();
$res = $pa->getValue($var, '[12]');

@javiereguiluz
Copy link
Member

A more realistic benchmark would be to use range(1, 1000) or so. In any case, impressive numbers! Thanks for the optimization.

@nicolas-grekas
Copy link
Member Author

And one with setValue:
https://blackfire.io/profiles/compare/15688eff-7e1b-48fb-9d97-c6f22278603c/graph
capture du 2016-03-18 15 40 35

$var = range(1, 100000);
$pa = new PropertyAccessor();
$res = $pa->setValue($var, '[12]', $var);

@stof
Copy link
Member

stof commented Mar 21, 2016

These numbers are very impressive.

@nicolas-grekas can you also post a benchmark for a deeper property path ?

👍
Status: reviewed

@fabpot
Copy link
Member

fabpot commented Mar 21, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 72940d7 into symfony:2.3 Mar 21, 2016
fabpot added a commit that referenced this pull request Mar 21, 2016
…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
@nicolas-grekas nicolas-grekas deleted the fix-ref-mismatch branch March 21, 2016 16:50
@webmozart
Copy link
Contributor

Awesome, thanks @nicolas-grekas :)

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.

6 participants