Skip to content

Cache aliased uses per file in AliasUsesResolver - #8684

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
tv-alias-uses-cache
Closed

TomasVotruba wants to merge 1 commit into
mainfrom
tv-alias-uses-cache

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

What

AliasClassNameImportSkipVoter runs once per FullyQualified node during name importing. Each call delegated to AliasUsesResolver::resolveFromNode(), which re-traversed the whole file stmts to collect use X as Y names - even though that result is file-global and identical for every node in the pass.

A file with N fully-qualified names did N full stmt traversals to compute the same alias list N times, on every convergence iteration.

Change

  • AliasUsesResolver now caches the aliased-use list per file, keyed by File identity + getNewStmtsVersion() - same invalidation pattern already used by ShortNameResolver::resolveShortClassLikeNames().
  • New resolveFromFile(File) replaces resolveFromNode(Node, array); the voter calls it. The removed node argument was only ever type-checked, never a namespace node, so behavior is unchanged.
  • Cache invalidates when stmts version bumps, so added imports across iterations are still seen.

One traversal per file stmts version instead of one per imported name.

Tests

Existing import suites green (rules-tests/CodingStyle/ClassNameImport, ImportFullyQualifiedNamesRector, tests/Issues/AutoImport*, NamespacedUseAutoImport, docblock import) - 148 tests. ECS + PHPStan clean on changed files.

First small step toward collapsing the per-node skip-voter re-traversals behind a single per-file import context.

@TomasVotruba
TomasVotruba deleted the tv-alias-uses-cache branch October 17, 2026 15:14
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.

1 participant