Repository navigation
perf: cut parser, cleanup and e6 generator overhead in subquery-tree conversion - #329
Merged
tkaunlaky-e6 merged 1 commit intoOct 28, 2026
Conversation
…conversion - parser: inline hot helpers (_advance, Expression.__init__, Parser.expression), fast exits in _parse_types, _parse_select_query, _parse_range and _parse_bitwise when no matching token follows, inlined _match_set in operator-precedence loops, faster _match_text_seq and update_positions - helpers: normalize_unicode_spaces as precompiled regexes (fast path when nothing to replace); apply_e6_ast_transforms as an explicit stack walk - e6: build the quote_identifier keyword set once at module level; indent fast path when no line toggles quote state Output is identical on all 1,628 Samsung + Conde Nast queries (both tokenizers, pretty on and off). Test suite unchanged: 937 passed / 4 skipped (Python tokenizer), 940 passed / 1 skipped (Rust tokenizer).
tkaunlaky-e6
merged commit Oct 28, 2026
6431a11
into
codex/experiment-dialect-regions
1 check passed
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.
Speed-only changes on top of
codex/experiment-dialect-regions. The flow is unchanged: same region discovery, same Postgres-first / Databricks-fallback, same output.Changes
Parser (
sqlglot/parser.py,sqlglot/expressions.py)_advance,Expression.__init__parent setting, andParser.expressioncomments and validation._match_setin the 8 operator-precedence loops; faster_match_text_seqandupdate_positions._parse_types,_parse_select_query(guarded against dialect overrides), and_parse_range/_parse_bitwise.Cleanup + transforms (
apis/utils/helpers.py)normalize_unicode_spacesuses precompiled regexes, returning early when there is nothing to replace. It was a character-by-character loop costing about 4% of all CPU.apply_e6_ast_transformswalks the tree with an explicit stack instead oftree.transform.e6 generator (
sqlglot/dialects/e6.py)quote_identifierused to rebuild a 690-word keyword set on every identifier; it is now a module-levelfrozenset. This is most of thee6.pydiff: the set moves from inside the method to module level.indentfast path when no line toggles the quote state, which is the common case.Verification
Benchmark
Dockerfile, base vs. this branch. Both run side by side, each container pinned to its own CPU with 2 GB.benchmarks/four_way.pycalling the realconvert_query, with all 1,628 queries, 3 passes, and each query's median.Peak memory is unchanged (295 → 291 MiB Rust, 274 → 273 MiB Python). The 18 errors are the same queries on both sides.
Notes
_parse_select_query,_parse_rangeand_parse_bitwiserely on lists of the tokens each function reacts to. If one of those functions learns a new token, it must be added to the matching list.0x/0bliterals and digit-leading names (separate change).