Skip to content

perf: dialect-regions optimizations, benchmark cleanup and MULTIDIALECT-only trigger - #333

Merged
tkaunlaky-e6 merged 17 commits into
wip/e6-multidialect-subquery-treefrom
codex/experiment-dialect-regions
Oct 30, 2026
Merged

tkaunlaky-e6 merged 17 commits into
wip/e6-multidialect-subquery-treefrom
codex/experiment-dialect-regions

Conversation

@tkaunlaky-e6

@tkaunlaky-e6 tkaunlaky-e6 commented Oct 29, 2026 •

Copy link
Copy Markdown

Brings the dialect-regions performance work into wip/e6-multidialect-subquery-tree, removes the benchmark artifacts, and makes SUBQUERY_TREE a method switch instead of a trigger.

Commits

  • perf: skip parser probes, generator and pipeline work that can never match — early exits in the parser when the next token can't start what is being probed (alias, set operation, window, lambda tail on ) / , / end; interval only on INTERVAL; AT TIME ZONE only on AT), inlined look-ahead and comment checks, precomputed mandatory arg keys, maybe_comment only for nodes with comments, e6 indent single-line shortcut, index-based LiteParser._skip, direct e6 transform walk, substring pre-checks before the STRUCT and unicode-space regexes.
  • chore: remove benchmark reports, scripts and result dumps — the 91 files under benchmarks/ added on this branch (reports, scripts, results/). Nothing imports them; the upstream benchmarks/ files stay.
  • Merge wip/e6-multidialect-subquery-tree — one conflict in converter_api.py: wip's HYBRID layout is kept and the subquery-tree call uses emit_tokens so region tokens are reused.
  • style: ruff format and mypy fixes — formatting the subtree/hybrid/region-token files, small type fixes in lite_parser, subquery_tree, region_tokens, _region_to_e6, and converter_api added to the mypy ignore list next to guardrail (the corpus tests import it).
  • fix(e6): trigger the multidialect path only from the MULTIDIALECT flag — SUBQUERY_TREE now only picks the method (subquery tree vs split_pg_outer); the path is triggered by the MULTIDIALECT feature flag or SAMSUNG_TABLEAU_DASHBOARD. Before, a deployment with SUBQUERY_TREE on sent every request through the tree, plain single-dialect ones included.

Flags

Flag Kind Effect
MULTIDIALECT request feature flag (sent by the planner when ENABLE_MULTIDIALECT_TRANSPILE is on) triggers the multidialect path
SUBQUERY_TREE deployment env inside that path: true = subquery tree, false = old split
SAMSUNG_TABLEAU_DASHBOARD deployment env unchanged
HYBRID_MULTIDIALECT deployment env unchanged (Freshworks)

Testing

  • make check: style (ruff, ruff-format, mypy) passes; make test and make test-rs pass.
  • Subtree and MULTIDIALECT return the same e6 on every Samsung (704), Condé Nast (858 all_match) and OneTrust query.
  • New test: SUBQUERY_TREE on without MULTIDIALECT does not reach the tree.

Performance vs wip/e6-multidialect-subquery-tree

Measured on this PR's head in Docker: 1 CPU per container, 3 repeats, the same 1,628 Samsung + Condé Nast queries; output identical on all 1,628.

Tokenizer Pretty Mean ms / query p95 ms ≥100k-char queries
Rust on 86.6 → 47.1 (−45.6%) 775.1 → 418.1 (−46.1%) 893.0 → 480.1 (−46.2%)
Rust off 79.3 → 46.8 (−40.9%) 694.8 → 421.6 (−39.3%) 811.9 → 476.4 (−41.3%)
Python on 116.8 → 66.7 (−42.9%) 1036.6 → 560.7 (−45.9%) 1193.5 → 669.0 (−43.9%)
Python off 108.8 → 62.9 (−42.1%) 943.2 → 527.5 (−44.1%) 1103.7 → 629.8 (−42.9%)

Samsung only (704 queries), Rust, pretty on:

Query size Queries Mean time per query Median p95 Total
All 704 194.9 → 105.5 ms (−45.9%) 65.5 → 35.6 ms (−45.7%) 987.8 → 534.9 ms (−45.9%) 137.2 → 74.3 s
<5k chars 254 3.6 → 2.4 ms (−34.2%) −36.3% −45.3% 0.9 → 0.6 s
5k–20k 48 16.4 → 10.0 ms (−39.0%) −45.1% −47.2% 0.8 → 0.5 s
20k–100k 295 135.4 → 74.0 ms (−45.4%) −14.5% −41.3% 40.0 → 21.8 s
≥100k 107 893.0 → 480.1 ms (−46.2%) 968.5 → 518.1 ms (−46.5%) 1044.1 → 572.4 ms (−45.2%) 95.6 → 51.4 s

Peak RSS is about 20 MB higher (271 → 292 MiB).

sudarsanl and others added 17 commits October 13, 2026 16:05
…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).
perf: cut parser, cleanup and e6 generator overhead in subquery-tree conversion
…match

- parser: return early when the next token can't start what is being probed
  (alias, set operation, window, lambda tail on ")"/","/end; interval only on
  INTERVAL; AT TIME ZONE only on AT), inline bracket/look-ahead/comment checks in
  _parse_bracket, _match, _parse_select and _parse_function
- expressions: precompute each class's mandatory arg keys for error_messages
- generator: call maybe_comment only for nodes that have comments; e6 cast_sql
  compares the INTERVAL type directly; e6 indent returns early for single lines
- pipeline: LiteParser._skip scans by index and advances once; the e6 transform
  walk reads node.args directly; plain substring pre-checks before the STRUCT and
  unicode-space regexes

Test suite unchanged: 937 passed / 4 skipped (Python tokenizer), 940 passed /
1 skipped (Rust tokenizer).
They documented the measurements behind the region-token and parser changes; nothing
imports them. Keeps the upstream benchmarks/ (bench, optimize, parse).
…e' into codex/experiment-dialect-regions

# Conflicts:
#	converter_api.py
- ruff format the files the subtree/hybrid/region-token work left unformatted
- lite_parse: cast the parsed tree to its declared return type
- parse_region: name the token-reuse parse result separately so mypy sees the None check
- region_tokens: '# type: ignore' the sqlglotrs import, as sqlglot.tokens does
- _region_to_e6: from_sql is Optional (the subquery tree passes None)
- setup.cfg: skip mypy errors in converter_api, as for guardrail (tests now import it)
SUBQUERY_TREE now only picks the multidialect method (subquery tree vs split_pg_outer); the
path itself is triggered by the MULTIDIALECT feature flag (or SAMSUNG_TABLEAU_DASHBOARD).
Before, a deployment with SUBQUERY_TREE on sent every request through the subquery tree,
plain single-dialect ones included, ignoring from_sql.

The corpus tests' subtree mode now sends MULTIDIALECT, and a test pins that SUBQUERY_TREE
alone does not reach the tree.
@github-actions

Copy link
Copy Markdown

Benchmark for 40c397a

Click to view benchmark
Test Base PR %
long 227.7±6.04µs 163.2±2.41µs -28.33%

@tkaunlaky-e6
tkaunlaky-e6 merged commit cae1417 into wip/e6-multidialect-subquery-tree Oct 30, 2026
2 checks passed
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.

2 participants