perf(optimizer): skip redundant hash invalidation in simplify's pointer-reset loop#7725
Open
tobymao wants to merge 1 commit into
Open
perf(optimizer): skip redundant hash invalidation in simplify's pointer-reset loop#7725tobymao wants to merge 1 commit into
tobymao wants to merge 1 commit into
Conversation
…er-reset loop _simplify's post-order pass re-anchors every child's parent/arg_key/index pointers via set(), which also clears cached structural hashes up the ancestor chain. The loop never changes values (it rewrites args[k] with itself), and actual mutations already invalidate at mutation time through set/replace/pop, so the only effect of the extra invalidation was forcing while_changing to rehash entire condition subtrees after every (mostly no-op) pass to detect the fix point. Fix pointers directly with _set_parent, preserving set(k, None)'s arg-removal semantics. Simplify step ~5-12% faster across condition and TPC fixtures; output is byte-identical.
Contributor
SQLGlot Integration Test Results✅ All tests passedComparing: Overallmain: 192441 total, 153536 passed (pass rate: 79.8%) sqlglot:perf/simplify-speedups: 180247 total, 142391 passed (pass rate: 79.0%) Transitions: Dialect pair changes: 0 previous results not found, 3 current results not found ✅ All tests passed |
georgesittas
approved these changes
Jun 10, 2026
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.
_simplify's post-order pass re-anchors childparent/arg_key/indexpointers viaoriginal.set(k, v). Besides fixing pointers,set()clears cached structural hashes up the ancestor chain — but this loop never changes a value, and real mutations already invalidate throughset/replace/pop. The wasted invalidation forcedwhile_changingto rehash entire condition subtrees on every (mostly no-op) pass just to detect the fix point.Fix pointers directly with
_set_parent, preservingset(k, None)'s arg-removal semantics. Safe because__hash__only coverskey+argsvalues, which this loop doesn't touch.Simplify step is ~5-12% faster (condition and TPC fixtures), full
optimize()~2%. Optimized output is byte-identical on all fixtures; pure and compiled suites green.