[Performance] Resolve class-like names once per file version in Short… - #8524
Merged
Merged
Conversation
Member
|
Very nice work, improvement is quite clear 👍 how did you spot this? End-to-end bench — base 5b56397 vs PR 8524 Real bin/rector process --dry-run --clear-cache, single process, synthetic tree: 200 files × 150 FQ names each, config = withImportNames() + 1 non-matching rule. Both branches produced identical result (200 files changed) — correct. |
TomasVotruba
force-pushed
the
perf/name-import-skip
branch
from
October 1, 2026 08:04
fa81113 to
879faa0
Compare
TomasVotruba
enabled auto-merge (squash)
October 1, 2026 08:05
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.
With
withImportNames(),ClassLikeNameClassNameImportSkipVotercallsShortNameResolver::resolveShortClassLikeNames()for every name it checks. Each call searches the whole file for class-likes, so in big files the cost grows with names × nodes (see rectorphp/rector#8077).The class-likes of a file only change between two passes of
FileProcessor. So I cache the result per file and per version of the stmts.File::changeNewStmts()increases the version.What I measured (CPU instructions, same input, same output):
One thing I noticed: since #8370 the order of the skip voters depends on the filesystem. On my Mac this voter runs before
OriginalNameImportSkipVoter, so it also runs for names that are already imported. WhenOriginalNameImportSkipVoterruns first, the gain on our project is only about 3 %.@TomasVotruba could you try it on your machine and tell me what you think? If a fixed order with the cheap voters first makes sense to you, I can send it as a separate PR.