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

[PropertyAccess] speed up accessing object properties #29999

Merged
merged 1 commit into from Jan 30, 2019

Conversation

@xabbuh
Copy link
Member

xabbuh commented Jan 27, 2019

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

@xabbuh xabbuh added this to the next milestone Jan 27, 2019

@xabbuh xabbuh force-pushed the xabbuh:pr-29405 branch from 0b57009 to 7218c2c Jan 27, 2019

@xabbuh xabbuh added the Performance label Jan 27, 2019

@fbourigault

This comment has been minimized.

Copy link
Contributor

fbourigault commented Jan 27, 2019

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, '[')) {

This comment has been minimized.

@ostrolucky

ostrolucky Jan 27, 2019

Contributor
Suggested change Beta
if (\is_object($objectOrArray) && false === strpos((string) $propertyPath, '.') && false === strpos((string) $propertyPath, '[')) {
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {

This comment has been minimized.

@xabbuh

xabbuh Jan 27, 2019

Author Member

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.

This comment has been minimized.

@fbourigault

fbourigault Jan 28, 2019

Contributor

According to https://blackfire.io/profiles/compare/f5b0113a-fcae-41cc-9b83-3bdd48c8bcf5/graph using strpbrk is faster than strcspn + strlen.

Show resolved Hide resolved src/Symfony/Component/PropertyAccess/PropertyAccessor.php Outdated
@fbourigault

This comment has been minimized.

Copy link
Contributor

fbourigault commented Jan 27, 2019

Here is a profile of this PR (with @ostrolucky suggestions ; single strpbrk is slightly faster than two strpos) vs master : https://blackfire.io/profiles/compare/487eef43-6de6-4e82-954d-a08dc7c90e65/graph

@xabbuh xabbuh force-pushed the xabbuh:pr-29405 branch from 7218c2c to ef7876e Jan 27, 2019

@fabpot

fabpot approved these changes Jan 30, 2019

@fabpot

This comment has been minimized.

Copy link
Member

fabpot commented Jan 30, 2019

Thank you @xabbuh.

@fabpot fabpot merged commit ef7876e into symfony:master Jan 30, 2019

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Jan 30, 2019

feature #29999 [PropertyAccess] speed up accessing object properties …
…(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

@xabbuh xabbuh deleted the xabbuh:pr-29405 branch Jan 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment