Repository navigation
perf(e6): pause GC per /convert-query, port upstream parser fast paths, bound log_records - #341
Merged
Merged
Conversation
…s, bound log_records - converter_api: disable the cyclic GC during /convert-query and collect once at the end (finally); gc.freeze() after startup. sqlglot ASTs are cyclic, so the GC kept rescanning the growing tree and the previous request's dead one. - parser/expressions: port upstream fast paths (18f15ca inlined _parse_tokens, 489ba1d column fast path + is_primitive, c95ae50 literal fast path, ec7b3d8 expression-first _parse_select_or_expression). - log_collector: log_records is a deque(maxlen=1000). 3.8 MB Tableau query, Docker 7 CPU: 9-11 s -> 5.4-6.2 s sequential, 4 concurrent worst 22.8 s -> 8.4 s. Outputs identical on nov_4th (14,840) and Samsung (704).
suyashkhare1403
approved these changes
Nov 23, 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.
Why
Under the samsung-dashboard stress test, one 3.8 MB Tableau query (about 20k
ORbranches, 24kINlists) took 27 s in the transpiler on the old path, and 57 s withSUBQUERY_TREEwhile other users ran queries in parallel. Profiling showed three problems:log_recordsgrows forever. Each worker keeps every log line, including the full converted query: about 8 KB per normal query, 67 KB per Samsung query, and 3.8 MB for this one.What
sqlglot/parser.py,sqlglot/expressions.pyconverter_api.py/convert-queryand collects once at the end, infinally. Callsgc.freeze()once after startup so that collect stays cheap. The handler has noawait, so requests never interleave while the GC is paused.log_collector.pylog_recordsis now adeque(maxlen=1000)./statisticsand/guardstatsare deprecated.tests/test_subquery_tree.pyThe parser ports:
_parse_tokensinto the disjunction, conjunction, comparison and exponent parsers.is_primitiveon Literal, Identifier, Var and Boolean, which skips validation and parent wiring for them._parse_type._parse_select_or_expressiontries the expression first.The fast paths fall back to the normal path wherever a dialect override applies (Postgres
_parse_field, the Databricks string merge and quoted qualifier, DuckDB#n, Teradata(FORMAT ...)).Results
Docker, 7 CPUs, the 3.8 MB query, samsung-dashboard config (
SUBQUERY_TREE, Rust tokenizer, STRIP flags). main and this branch ran back to back. Client times:Postgres parse alone on this query: 4.9 s → 3.4 s.
Verified
make testandmake test-rs: 1065 tests OK.make test-multidialect(Samsung / Condé Nast / OneTrust): OK.sqlglot/_version.py, which is unrelated.