Skip to content

Widen the join of conditional expression holders with the same guards - #7214

Merged
ondrejmirtes merged 2 commits into
2.3.xfrom
widen-conditional-holder-joins
Nov 27, 2026
Merged

ondrejmirtes merged 2 commits into
2.3.xfrom
widen-conditional-holder-joins

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

MutatingScope::mergeSameGuardConditionalExpressions() joined the types of conditional expression holders across branches with the exact TypeCombinator::union() only. Since 4268fd0 moved generalization of big constant arrays from union() to TypeCombinator::widen(), and 0e9fdb5 stopped merging shapes that differ at several keys, these joins grew without bound. The issue's loop held about 70 shapes of 15 keys per holder and ran 2770 such unions in one loop pass. The join is now widened, like the joins of scopes in ExpressionTypeHolder::and(). The native mirror in turbo-ext/src/MutatingScope.cpp does the same.

  • Issue repro (tests/bench/data/bug-15862.php, bench config): 57.4 s → 5.4 s
  • mailpoet ReporterCampaignData.php: killed at 50 s with 860 MB and rising → 12.6 s, 190 MB (c3874c8, before the regression: 5.8 s)

The remaining gap on the mailpoet file comes from the exact unions of 4+4 shapes with 60 keys that run before widen() folds them. It is not addressed here.

Closes phpstan/phpstan#15862

Amp thread: https://ampcode.com/threads/T-01a21c4b-0cd2-7583-a39a-cf304ee8e07b

mergeSameGuardConditionalExpressions() joined the types of conditional
holders across branches with the exact union() only. Since union() no
longer generalizes big constant arrays itself, these joins grew without
bound: a loop bumping counters of a 15-key shape in if/elseif chains
inside a switch held about 70 shapes per holder and took 57 s. The join
is now widened like the joins of scopes in ExpressionTypeHolder::and().

Closes phpstan/phpstan#15862

Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4b-0cd2-7583-a39a-cf304ee8e07b
@ondrejmirtes
ondrejmirtes merged commit 275173e into 2.3.x Nov 27, 2026
893 of 917 checks passed
@ondrejmirtes
ondrejmirtes deleted the widen-conditional-holder-joins branch November 27, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analysis of a loop over a large counter array explodes in time and memory (since phpstan-src 4268fd0b3 and 0e9fdb53e, #7195)

1 participant