-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add getVisitorsForNode() method to NodeTraverser #1122
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
base: master
Are you sure you want to change the base?
Conversation
|
Ready for review 👍 |
|
In the case of Rector, this was used to optimise the running time by 20-30%. Probably other tools could benefit from similar optimisations |
|
The 20-30 % speedup was really noticable across many mid-large size projects 👍 |
|
It looks like adding this method makes NodeTraverser itself about 10% slower. |
|
@nikic could you share script to verify the benchmark? Thank you. |
|
@nikic I created benchmark repo for non-cached vs cached node visitor version https://github.com/samsonasik/php-parser-with-cache-node-visitor-benchmark which shows faster result on total time.
|

@TomasVotruba here for your request rectorphp/rector-src#6232 (comment)
This is template config for
getVisitorsForNode(), which on rector use case, we use for caching visitor by node.https://github.com/rectorphp/rector-src/blob/4b30bc5d10e7c79867a6a13da3a75a1b2c844675/src/PhpParser/NodeTraverser/RectorNodeTraverser.php#L65-L82
so we can just override the method there :), we currently using vendor-patch for it:
https://github.com/rectorphp/vendor-patches/blob/18e174cbea7beaccb140cfcf03cca3097e95ee92/patches/nikic-php-parser-lib-phpparser-nodetraverser-php.patch
Original PR for this usage for caching on Rector side: