Skip to content

[TypeDeclaration] Speed up BinaryOpNullableToInstanceofRector by skipping bool-shaped operands - #8607

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-perf-binaryop-nullable
Oct 10, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv-perf-binaryop-nullable

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Perf

BinaryOpNullableToInstanceofRector fires on every BooleanAnd/BooleanOr and calls resolveNullableObjectType() (which runs full native type resolution) on both operands. An operand that is itself bool/scalar-shaped can never be a nullable object, so that type resolution is wasted - most notably in chained conditions like $a && $b && $c, which parse as ($a && $b) && $c where the left operand is a nested BooleanAnd.

Added a cheap structural guard that skips resolveNullableObjectType() when the operand is a BinaryOp, BooleanNot, Instanceof_, Empty_ or Isset_. These always resolve to a non-object type, so the result is unchanged - only the scope lookup is avoided.

@TomasVotruba
TomasVotruba merged commit e54efe3 into main Oct 10, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-perf-binaryop-nullable branch October 10, 2026 22: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.

2 participants