Repository navigation
[perf] Add static node-rule map for O(1) visitor lookup - #8544
Draft
TomasVotruba wants to merge 6 commits into
Draft
TomasVotruba wants to merge 6 commits into
TomasVotruba wants to merge 6 commits into
Conversation
TomasVotruba
force-pushed
the
worktree-static-node-rule-map
branch
3 times, most recently
from
October 8, 2026 20:59
ad378dd to
fca12ef
Compare
TomasVotruba
marked this pull request as draft
October 8, 2026 21:01
TomasVotruba
force-pushed
the
worktree-static-node-rule-map
branch
from
October 10, 2026 09:29
fca12ef to
503127a
Compare
Precompute a node-class to rule map for core + symfony/doctrine/phpunit rules, shipped as config/node-rule-map.json. RectorNodeTraverser uses it to resolve visitors per node class without looping all rules on cold cache. Rules missing from the map (e.g. third-party) fall back to the is_a loop.
The static map file is immutable, decode it once instead of on every prepareNodeVisitors() / refreshPhpRectors().
TomasVotruba
force-pushed
the
worktree-static-node-rule-map
branch
from
October 10, 2026 09:41
fe529b4 to
2beb0ef
Compare
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.
Why
RectorNodeTraverser::getVisitorsForNode()is cached per node class, but the first hit for each node class loops every active rule (~600-700) and callsgetNodeTypes()+is_a()on each. Cold-cache cost on every distinct node class.What
config/node-rule-map.json: concrete node class -> rule FQCN list, is_a-resolved (soNode/ClassLike/CallLikesubscribers are folded in per concrete node). Covers core rules + symfony/doctrine/phpunit.getVisitorsForNode()now does an O(1) map lookup, keeps only the active rules, and orders them by their registration position. No per-node foreach over all rules.is_aloop, so behavior is preserved.build/build-node-rule-map.php(composer build-node-rule-map) reusesRectorClassFinderand filters toRectorInterface(PostRectors excluded). Output is deterministic (sorted).Node Rule Map Up To Dateregenerates and fails on drift, so a listed rule changing its node types cannot silently go stale.Tests
RectorNodeTraverserTestextended with a static-map resolution case; existing cases still pass.rules-testssuite exercises the map path with real rules.