Skip to content

[TypeDeclaration] Speed up AddReturnTypeDeclarationRector with cheap method-name gate before type resolution - #8655

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-perf-add-return-type
Oct 15, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-perf-add-return-type

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The rule subscribes to every Class_ node and loops over all configured AddReturnTypeDeclaration entries, calling isObjectType() on each. isObjectType() resolves the node type via getType(), which is not cached, so for a config with K entries the same class type is resolved K times per class - even for entries whose target method the class does not even declare (symfony/doctrine/phpunit sets configure dozens of entries).

This adds a cheap method-name gate: build the set of method names on the class once (plain AST, lowercased to match the case-insensitive isName), and skip an entry before the expensive isObjectType() when the class has no method of that name. The existing inner isName loop is kept unchanged as the authority, so the gate can only false-positive (then the inner loop rejects as before), never false-negative - behavior is identical.

Tests, ECS and PHPStan pass locally.

@TomasVotruba
TomasVotruba merged commit 92f0c3a into main Oct 15, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-add-return-type branch October 15, 2026 14:54
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