Skip to content

[perf] Speed up type declaration rules with cheap structural and name guards before reflection - #8661

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-perf-cheap-guard-before-reflection-finder
Oct 15, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv-perf-cheap-guard-before-reflection-finder

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Performance refactor of 7 rules. No behavior change - all fixtures pass unchanged.

Each rule ran a reflection or ancestry call before a cheap structural or name check that can bail first:

  • AddVoidReturnTypeWhereNoReturnRector - the isNotFinalAndHasExceptionOnly()/isNotFinalAndEmpty() guards now check the single-statement / empty-body shape before isInsideFinalClass() (reflection).
  • KnownMagicClassMethodTypeRector - name filter (the handled magic methods) now runs before hasParentClassMethod(), so non-handled magic methods (__construct, __toString, __invoke, ...) skip the parent lookup. The now-redundant second name check is folded away.
  • AddParamTypeDeclarationRector - a class with no parent and no interfaces has no param type to mimic, so it bails before isTypeGuardedClass().
  • ReturnNeverTypeRector - the native returnType check runs before isInTestClass().
  • AddPropertyTypeDeclarationRector - property name match runs before the reflection type check in the config loop.
  • TypedPropertyFromDocblockSetUpDefinedRector - the setUp() method lookup runs before isInTestClass().
  • AddReturnTypeDeclarationFromYieldsRector - the already-filled iterator return type check runs before the yield-node subtree walk.

Reordering is safe: all moved checks are side-effect-free bail conditions that must all pass to proceed.

@TomasVotruba
TomasVotruba merged commit de0b01d into main Oct 15, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-cheap-guard-before-reflection-finder branch October 15, 2026 11:25
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