Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Jan 30, 2019

Conversation

xabbuh
Copy link
Member

@xabbuh 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:

@fbourigault
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, '[')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

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.

Copy link
Contributor

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.

@fbourigault
Copy link
Contributor

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

@fabpot
Copy link
Member

fabpot commented Jan 30, 2019

Thank you @xabbuh.

@fabpot fabpot merged commit ef7876e into symfony:master Jan 30, 2019
fabpot added a commit that referenced this pull request Jan 30, 2019
…(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 pr-29405 branch January 30, 2019 13:06
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
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.

8 participants