-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] speed up accessing object properties #29999
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
As this provide almost identical performance boost (~ 20/30% perf improvement). I would prefer merging this and do further profiling to improve serializer performance. |
$zval = [ | ||
self::VALUE => $objectOrArray, | ||
]; | ||
|
||
if (\is_object($objectOrArray) && false === strpos((string) $propertyPath, '.') && false === strpos((string) $propertyPath, '[')) { |
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.
if (\is_object($objectOrArray) && false === strpos((string) $propertyPath, '.') && false === strpos((string) $propertyPath, '[')) { | |
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { |
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.
Updated, though I wonder if using strcspn()
and comparing that with strlen()
would be better in that it doesn't required to copy a string.
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.
According to https://blackfire.io/profiles/compare/f5b0113a-fcae-41cc-9b83-3bdd48c8bcf5/graph using strpbrk
is faster than strcspn
+ strlen
.
Here is a profile of this PR (with @ostrolucky suggestions ; single |
Thank you @xabbuh. |
…(xabbuh) This PR was merged into the 4.3-dev branch. Discussion ---------- [PropertyAccess] speed up accessing object properties | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28926, #29405 | License | MIT | Doc PR | I propose to improve the performance of the `ObjectNormalizer` by not adding a new interface to the PropertyAccess component, but by adding some shortcut for cases where we know that we do not need to perform all checks. The added benefit is that this will not only speed up the `ObjectNormalizer` class, but will be available for every consumer of the `PropertyAccessor` without having to adapt to a new API. TODO: - [ ] confirm that these changes indeed introduce the same benefit as #29405 doing an actual benchmark Commits ------- ef7876e speed up accessing object properties
I propose to improve the performance of the
ObjectNormalizer
by not adding a new interface to the PropertyAccess component, but by adding some shortcut for cases where we know that we do not need to perform all checks. The added benefit is that this will not only speed up theObjectNormalizer
class, but will be available for every consumer of thePropertyAccessor
without having to adapt to a new API.TODO: