Repository navigation
Revisit only newly guarded expressions in conditional-expression matching rounds - #7232
Merged
Merged
Conversation
…hing rounds matchConditionalExpressions() repeated full passes over every holder of the scope until no new expression was specified. An expression unmatched in one round can only match in a later one once one of its guards got matched, so after the first round the unmatched expressions are indexed by their guards and later rounds revisit only the ones guarded by an expression matched since. The matches and their order are unchanged. Both passes also check a holder's guards before its certainty, as the guards usually rule it out first. Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
ondrejmirtes
force-pushed
the
index-holders-by-guard
branch
from
November 27, 2026 20:29
b7ded4a to
f3b91d7
Compare
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.
ScopeOps::matchConditionalExpressions()repeated full passes over every conditional expression holder in the scope until no new expression got specified. It runs on everyapplySpecifiedTypes(), so in code with many stored conditions it does quadratic work.An expression that stays unmatched in one round can only match in a later one once one of its guards gets matched. Its other guards read the same specified values as before. So after the first round, the unmatched expressions are indexed by their guards, and later rounds revisit only the expressions guarded by one matched since. That includes expressions matched earlier in the same round, so the matches and their order are exactly the same.
Both passes also check a holder's guards before its certainty. The guards usually rule a holder out with one
array_key_exists, before the three method calls of the certainty check.On 800 statements of
$xN = $in[N]; $okN = $xN !== null; if ($okN) …, analysis goes from 21.8 s to 14.0 s with the same output. The new benchmarktests/bench/data/many-stored-conditions.php(150 such statements) is about 12% faster locally.The first round still scans every holder, and invalidation still scans every key. Both would need indexes kept in the scope itself, which this PR doesn't do.
The C++ mirror in
ScopeOps.cppis updated. Walk-trace is identical, and the full suite passes with and without the extension.