Skip to content

[Visibility] Speed up ChangeConstantVisibilityRector with cheap constant-name gate before type resolution - #8673

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-perf-const-visibility
Oct 16, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-perf-const-visibility

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Same perf pattern as #8655. The rule fires on every Class_/Interface_ node and loops over all configured ChangeConstantVisibility entries, calling isObjectType() on each before the cheap constant-name match happens in the nested loop. isObjectType() resolves the node type via the uncached getType(), so for K config entries the class type is resolved K times per node, even for entries whose target constant the class does not declare.

This adds a cheap constant-name gate: collect the class constant names once (plain AST), and skip an entry before isObjectType() when the class has no constant of that name. The gate mirrors isName semantics on ClassConst exactly - first declared const per statement, lowercased to match the case-insensitive strcasecmp - so it can only false-positive (then the existing inner isName loop rejects as before), never false-negative. Behavior is identical.

Tests, ECS and PHPStan pass locally.

@TomasVotruba
TomasVotruba merged commit 8b4baf6 into main Oct 16, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-const-visibility branch October 16, 2026 06:33
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