Skip to content

[perf] Speed up ArrayExplicitBoolCompareRector with cheap variable guard - #8603

Merged
TomasVotruba merged 1 commit into
mainfrom
perf-array-explicit-bool
Oct 10, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
perf-array-explicit-bool

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

This rule ran costly native type resolution on every If_/ElseIf_/Ternary node, twice per node:

  1. ExplicitBoolConditionResolver::resolve() -> getNativeType()
  2. ArrayTypeAnalyzer::isArrayType() -> getNativeType()

But the rule only ever rewrites a bare Variable condition (it bailed otherwise after both type calls already ran). getNativeType() is not cached and triggers scope resolution, so this was wasted work on the vast majority of conditions.

Changes:

  • Hoist the cheap Variable structural guard before any type resolution, so non-variable conditions bail instantly.
  • Collapse the two getNativeType() calls into one. A confirmed array type already excludes mixed and bool, so the resolver's native type check was redundant here.
  • Drop the now-unused ExplicitBoolConditionResolver dependency from this rule (still used by ObjectExplicitBoolCompareRector).

Behavior is unchanged - both fixtures still pass, and the skip fixture (a PropertyFetch condition) is now skipped with zero type resolution.

@TomasVotruba TomasVotruba changed the title [CodeQuality] Speed up ArrayExplicitBoolCompareRector with cheap variable guard [perf] Speed up ArrayExplicitBoolCompareRector with cheap variable guard Oct 10, 2026
@TomasVotruba
TomasVotruba merged commit 4f2f67f into main Oct 10, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the perf-array-explicit-bool branch October 10, 2026 21:31
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