Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[VarDumper] Improve performance of AbstractCloner #29777

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 25, 2019

Conversation

javiereguiluz
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

While profiling Symfony in "dev" environment (see #29762) I found that VarCloner::addCasters() was making thousands of strtolower() calls.

varcloner-addcasters

In this PR I propose to remove all those calls. I think it's possible to do it ... but I could be completely wrong, so please review.


As a side note, in the past we did the same strtolower() to service IDs and parameter names. We stopped doing that in Symfony 3.3 and it gave us a small performance improvement (same as we could gain here).

If the strtolower() calls of VarCloner::addCasters() are made just to apply the caster even if the class name is wrongly spelled, I think we could make this change. My guess is that nothing would break for the user (unlike removing the strtolower() in DependencyInjection, which broke wrongly spelled services and params). Thanks!

@ro0NL
Copy link
Contributor

ro0NL commented Jan 4, 2019

Alternatively we could lower all at once, before the foreach: array_change_key_case($caster, \CASE_LOWER). But if we can preserve types as-is that be 👍

@nicolas-grekas
Copy link
Member

This breaks case insensitivity of PHP identifiers (class names).
Can we reduce the number of calls to addCasters instead? What is calling it?

@nicolas-grekas
Copy link
Member

If we can't reduce the number of calls to addCaster, we could instead maintain a cache of type => lowercase(type) - there aren't many of them

@javiereguiluz
Copy link
Member Author

@nicolas-grekas you are right ... but we already broke PHP class name insensitivity in 3.3 when we made service IDs (= PHP FQCN) case sensitive. That's why I was wondering if we could do the same here to gain a bit of performance (combining #29762 and this PR it gave me an 8% improvement in the Symfony Demo app).

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 4, 2019

@javiereguiluz we broke case insensitivity of service identifiers, not of PHP classes as they're out of reach: that's the behavior of the PHP engine, no ways around.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Rebased, let's do this.

@nicolas-grekas nicolas-grekas changed the title Improve performance of AbstractCloner [VarDumper] Improve performance of AbstractCloner Jan 25, 2019
@nicolas-grekas
Copy link
Member

Thank you @javiereguiluz.

@nicolas-grekas nicolas-grekas merged commit cff23e5 into symfony:master Jan 25, 2019
nicolas-grekas added a commit that referenced this pull request Jan 25, 2019
…reguiluz)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[VarDumper] Improve performance of AbstractCloner

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | -   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | -

While profiling Symfony in "dev" environment (see #29762) I found that `VarCloner::addCasters()` was making thousands of `strtolower()` calls.

![varcloner-addcasters](https://user-images.githubusercontent.com/73419/50694461-40a1bd80-103a-11e9-83c0-a28b8f8f161e.png)

In this PR I propose to remove all those calls. I think it's possible to do it ... but I could be completely wrong, so please review.

-----

As a side note, in the past we did the same `strtolower()` to service IDs and parameter names. We stopped doing that in Symfony 3.3 and it gave us a small performance improvement (same as we could gain here).

If the `strtolower()` calls of `VarCloner::addCasters()` are made just to apply the caster even if the class name is wrongly spelled, I think we could make this change. My guess is that nothing would break for the user (unlike removing the `strtolower()` in DependencyInjection, which broke wrongly spelled services and params). Thanks!

Commits
-------

cff23e5 [VarDumper] Improve performance of AbstractCloner
@stof
Copy link
Member

stof commented Jan 25, 2019

As we rely on get_class and get_parent_class, this should be fine. These APIs always return classes with the case used when defining the class AFAIK.

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.