Repository navigation
[perf] Bucket method renames by old name in RenameMethodRector - #8734
Merged
Merged
Conversation
Per call/method node the rule scanned the whole configured rename list, running isStringName() on each before the type/reflection checks. With large sets (hundreds of renames) this is a per-node linear scan of pure string compares.
Bucket the renames by lowercased old-method name at configure() time, so a node only visits the renames sharing its name - one hash lookup instead of N comparisons. Behaviour is unchanged; isStringName() still runs on the matched candidates.
Also two small cleanups on the class-rename docblock path: reuse a single PhpDocNodeTraverser in DocBlockClassRenamer instead of allocating one per node, and hoist a loop-invariant getValue('type') lookup out of the per-class loop in PhpDocClassRenamer.
bench/rename_method_bucket_bench.php (400 renames, 200 non-matching calls): 159.9 -> 2.0 us/call.
…ClassRenamer The JMS @type rename path rebuilt the preg_quote word-boundary pattern per configured class per node; cache it by old class name.
Member
Author
|
Follow-up commit: |
This was referenced Oct 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RenameMethodRector is one of the few rules with real self cost (not triggered type resolution) in profiling - it scanned the whole configured rename list per call/method node, running
isStringName()on each entry before the type/reflection checks. With large sets (symfony/doctrine ship hundreds of renames) that is a per-node linear scan of pure string compares.Change
Bucket the renames by lowercased old-method name once at
configure()time. A node then only visits the renames that share its method name - a single hash lookup instead of N comparisons. Behaviour is unchanged:isStringName()still runs on the matched candidates, so theObject/case special-cases are preserved, and the type/reflection gating is untouched.Two small cleanups on the class-rename docblock path ride along:
DocBlockClassRenamerreuses a singlePhpDocNodeTraverserinstead of allocating one per node.PhpDocClassRenamerhoists a loop-invariantgetValue('type')lookup out of the per-class loop.Numbers
bench/rename_method_bucket_bench.php(400 renames, 200 non-matching calls, CPU time):The win scales with the size of the configured rename list. Full
rules-tests/Renamingsuite (107 tests) green, PHPStan and ECS clean.