Skip to content

[perf] Speed up return type rules with cheap structural bail before expensive scope guard - #8660

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-perf-structural-bail-before-override-guard
Oct 15, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-perf-structural-bail-before-override-guard

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Performance refactor of 5 return-type rules. No behavior change - all 29 fixtures pass unchanged.

Each rule ran a reflection-heavy guard (ClassMethodReturnTypeOverrideGuard::shouldSkipClassMethod(), or isInsideTestCaseClass() which walks the class ancestry) before the cheap structural precondition that the method/closure could even match. The cheap AST checks are now hoisted above the expensive guard, so non-matching nodes bail without paying for it.

  • ReturnTypeFromSymfonySerializerRector - single return $serializer->deserialize(...) shape (stmt count, Return_/MethodCall, name, first-class-callable) now checked before the override guard.
  • ReturnTypeFromReturnDirectArrayRector - hasReturnArray() before the override guard.
  • ReturnTypeFromStrictTernaryRector - single-return and Ternary shape before the override guard.
  • AddReturnTypeFromTryCatchTypeRector - return shape (hasOnlyReturnWithExpr()) before the override guard.
  • ClosureReturnTypeFromAssertInstanceOfRector - hasAssertInstanceOf() before the test-case ancestry check.

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

@TomasVotruba TomasVotruba changed the title [TypeDeclaration] Speed up return type rules with cheap structural bail before expensive scope guard [perf] Speed up return type rules with cheap structural bail before expensive scope guard Oct 15, 2026
@TomasVotruba
TomasVotruba merged commit a52288e into main Oct 15, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-structural-bail-before-override-guard branch October 15, 2026 10:45
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