Skip to content

[CodeQuality] Speed up ExplicitNullableObjectInstanceRector with cheap bail before native type resolution - #8652

Merged
TomasVotruba merged 1 commit into
mainfrom
perf-explicit-nullable-object-cheap-bail
Oct 14, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
perf-explicit-nullable-object-cheap-bail

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The If_/ElseIf_/Ternary branch of ExplicitNullableObjectInstanceRector runs through ExplicitBoolConditionResolver::resolve(), which calls getNativeType() on the condition of every single if/ternary in the analysed code - one of the hottest node shapes there is.

Most of those conditions can never be a nullable object: BinaryOp (comparisons, &&/||, ===), Instanceof_, Empty_, Isset_. This adds a cheap structural bail for those shapes before the costly native type resolution, so they skip it entirely.

Same pattern already used in the sibling BinaryOpNullableToInstanceofRector::isNeverNullableObject().

Behavior is unchanged - the skipped shapes already resolved to bool/non-object native types and returned null anyway.

@TomasVotruba
TomasVotruba merged commit 9c1a5c7 into main Oct 14, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the perf-explicit-nullable-object-cheap-bail branch October 14, 2026 21:08
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