[internal] Extract ImmutableNodeTraverser from vendor, to remove patch and keep using cache for node types#7634
Conversation
… of rector-src to avoid patching
6c6ff65 to
3999e3e
Compare
a0ff668 to
22d8f5f
Compare
22d8f5f to
c3f4873
Compare
|
cc @carlos-granados Hi Carlos, you might like this one... I'm making the immutable traverser part of the Rector core, so we have it without vendor patching 👍 Thanks for your innovation and work to make it happen 🚀 |
|
cc @staabm This is the immutable node traverser idea in new ImmutableNodeTraverser class. We saw 20-30 % performance improvements across various projects. I think PHPStan would benefit from this approach too. Tip for your next performance bottleneck hunting :) |
|
Let's ship this to test in real projects 🚀 |
|
@TomasVotruba A very interesting take. Only problem I can see is if somehow Nikic's PhpParser greatly modified their own parser, but I don't really see that happening |
|
@carlos-granados Thanks for feedback and welcome back 👍 (still travelling?) I was checking, and past ~3 years only one constant was added. I think we can handle the update + make the node traverser even faster for our purposes with similar caching you've introduced. |
|
huhu,
@TomasVotruba I looked thru the PR, but was not able to pin-point what in this PR makes it faster compared to before this PR. or does this PR implement the optimization which was already done in #6232 just in a different way? IIRC phpstan is already doing something similar: see #6232 (comment) |
|
@staabm Yes, it's same as #6232 , just without vendor patching. I pinged you now because I know vendor patching is very risky business (broken by PHPUnit recently), so would not recommend it. This PR implements the same logic that is easy to reproduce without touching vendor 👍 As for PHPStan, lazy registry saves some performance. Not sure how it's implemented on traverser level. |
Patching vendor yields many problems. This PR removes last non-stmts-aware patch of php-parser
It basically integrates this https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-nodetraverser-php.patch into our code. Without any patching or manual managing the
NodeVisitorchanges 👍How to run
What it does?
src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.phpfile that is identical toNodeTraverserwith one difference - it fetches node visitors viagetVisitorsForNode()abstract methodgetVisitorsForNode()with propper caching - no need to get all 500 rules forClass_node, maybe only those that matchgetNodeTypes()withClass_Builds on: #6232 by @carlos-granados