Skip to content

[Performance] Resolve class-like names once per file version in Short… - #8524

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
janwaleed09:perf/name-import-skip
Oct 1, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
janwaleed09:perf/name-import-skip

Conversation

@janwaleed09

Copy link
Copy Markdown
Contributor

With withImportNames(), ClassLikeNameClassNameImportSkipVoter calls ShortNameResolver::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):

  • our Symfony project with 4,500 files (import names + sets): 24 % fewer instructions, 17 % less CPU
  • one file with 2,000 fully qualified names: 122 → 80 billion instructions

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. When OriginalNameImportSkipVoter runs 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.

@TomasVotruba

Copy link
Copy Markdown
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.

┌──────┬─────────────────┬───────────────┬────────┐
│      │    User CPU     │     Wall      │  RSS   │
├──────┼─────────────────┼───────────────┼────────┤
│ BASE │ 185.1s / 180.1s │ 55.8s / 50.7s │ 145 MB │
├──────┼─────────────────┼───────────────┼────────┤
│ PR   │ 113.6s / 116.7s │ 29.0s / 13.7s │ 139 MB │
└──────┴─────────────────┴───────────────┴────────┘

@TomasVotruba
TomasVotruba force-pushed the perf/name-import-skip branch from fa81113 to 879faa0 Compare October 1, 2026 08:04
@TomasVotruba
TomasVotruba enabled auto-merge (squash) October 1, 2026 08:05
@TomasVotruba
TomasVotruba merged commit b540db7 into rectorphp:main Oct 1, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants