Repository navigation
Widen the join of conditional expression holders with the same guards - #7214
Merged
Merged
Conversation
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
From https://github.com/phpstan/phpstan-src/actions/runs/45992975831, the push run of 6a80bf9. The new benchmark had no numbers yet. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4b-0cd2-7583-a39a-cf304ee8e07b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MutatingScope::mergeSameGuardConditionalExpressions()joined the types of conditional expression holders across branches with the exactTypeCombinator::union()only. Since 4268fd0 moved generalization of big constant arrays fromunion()toTypeCombinator::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 inExpressionTypeHolder::and(). The native mirror inturbo-ext/src/MutatingScope.cppdoes the same.tests/bench/data/bug-15862.php, bench config): 57.4 s → 5.4 sReporterCampaignData.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