Skip to content

[perf] Speed up DeadCode rules with cheap guards before type checks, reflection and subtree walks - #8666

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-perf-dc-cheap-guard-before-type-walk
Oct 15, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-perf-dc-cheap-guard-before-type-walk

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

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

Each rule ran an expensive op (type resolution, reflection, or a side-effect/node-finder subtree walk) before a cheap check that can bail first:

  • RemoveFilterVarOnExactTypeRector - the filter-name membership check now runs before getNativeType(), so a filter_var() call with an unrelated filter constant skips the type lookup.
  • RemoveDeadZeroAndOneOperationRector - the literal 0/1 operand check now runs before areNumberType() (two isNumberType() type calls); an operation with no literal zero/one operand can never be dead, so it bails first.
  • RemoveParentCallWithoutParentRector - the cheap isAnonymousClass() check now runs before reflectionProvider->hasClass().
  • RemoveConditionExactReturnRector - the following-statement Return_ shape check now runs before sideEffectNodeDetector->detect().
  • RemoveOverriddenAssignBeforeIfElseRector - the next-statement if/else shape check now runs before matchOverridableAssignVariableName() (which walks for side effects).
  • RemoveDoubleAssignRector - the assign-target type check now runs before isSelfReferencing() and the findFirst() side-effect walk.
  • RemoveDeadInstanceOfRector - getNativeType() + object-type check now run before resolveClassReflection().

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

@TomasVotruba
TomasVotruba merged commit 2326ffe into main Oct 15, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-dc-cheap-guard-before-type-walk branch October 15, 2026 19:34
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