[PropertyAccess] speed up accessing object properties#29999
[PropertyAccess] speed up accessing object properties#29999fabpot merged 1 commit intosymfony:masterfrom
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. |
| self::VALUE => $objectOrArray, | ||
| ]; | ||
|
|
||
| if (\is_object($objectOrArray) && false === strpos((string) $propertyPath, '.') && false === strpos((string) $propertyPath, '[')) { |
There was a problem hiding this comment.
| 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.
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.
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
ObjectNormalizerby 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 theObjectNormalizerclass, but will be available for every consumer of thePropertyAccessorwithout having to adapt to a new API.TODO: