Skip to content
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

Performance: Improve node name resolver performance #3506

Merged
merged 4 commits into from
Mar 23, 2023

Conversation

keulinho
Copy link
Contributor

In #3502 we changed a lot of rectors to use isName over isObject, because isName is a lot faster.

But we can make it even faster. This contains two performance fixes:

  1. Don't loop every time through all node name resolvers:
    This code may be executed millions of times always looping to find the one name resolver can be improved by caching the used resolver per node class

  2. Checking if a string contains regex or fnmatch special chars before really analyzing if it is a regex pattern is much faster, as in most cases the desired name does not contain a special char

This brings another 10% performance increase in our test scenario: https://blackfire.io/profiles/compare/33d481dc-2a9d-439f-bed6-636f6eaaa8fa/graph
image

@keulinho keulinho requested a review from TomasVotruba as a code owner March 23, 2023 08:04
@keulinho
Copy link
Contributor Author

Will work on the phpstan errors later today ✌️

@keulinho keulinho force-pushed the improve-node-name-resolver branch from 760bf73 to 5915483 Compare March 23, 2023 12:48
Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

Looks good 👍 , let's give it a try

@samsonasik samsonasik merged commit 697479f into rectorphp:main Mar 23, 2023
@samsonasik
Copy link
Member

Thank you @keulinho

@keulinho keulinho deleted the improve-node-name-resolver branch March 23, 2023 15:36
samsonasik pushed a commit that referenced this pull request May 8, 2023
* Performance: Improve node name resolver performance

* Fix phpstan

* Add regex example link

* Fix CR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants