Repository navigation
perf(format): stop re-parsing and re-tokenizing work the formatter already has - #8
Merged
Merged
Conversation
…ready has Statement splitting in sqlclean format now parses the file and checks the statement count without collecting every statement's facts. The layout passes now take the printer's own token ranges instead of re-tokenizing the text it just printed. The final token check and the idempotence re-print still re-tokenize and compare, so every safety check stays. Amp-Thread-ID: https://ampcode.com/threads/T-01a18b8a-340f-717d-9ca7-6dcf564a065a Co-authored-by: Kevin Longe <kvlonge@gmail.com>
Deploying sqlclean with
|
| Latest commit: |
b4ce12f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8a1bf672.sqlclean.pages.dev |
| Branch Preview URL: | https://perf-formatter-redundant-wor.sqlclean.pages.dev |
This was referenced Oct 31, 2026
kvlonge
added a commit
that referenced
this pull request
Oct 31, 2026
…ready has (#8) Statement splitting in sqlclean format now parses the file and checks the statement count without collecting every statement's facts. The layout passes now take the printer's own token ranges instead of re-tokenizing the text it just printed. The final token check and the idempotence re-print still re-tokenize and compare, so every safety check stays.
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
Profiling
sqlclean formatshowed two pieces of repeated work. Statement splitting collected every statement's facts, such as tables, joins and columns, only to read the statement ends. Every print also re-tokenized the text the printer had just built from known tokens.Changes
statement_endsfunction givesformat_sourcethe statement boundaries. It still parses the whole file and checks the statement count, so files with opaque nodes or blocks that span semicolons are still refused, but it skips fact collection.file_factsshares the same helper.print_authored_tokensreturns the byte range and type of each token it printed, andPrintedSql::newbuilds from them instead of re-tokenizing.Verification
sqlclean formatoutput is byte-identical tomain.format --check, 4 CPUs, median of 5 runs: wall 2.97 s → 2.76 s (−7%), CPU 11.35 s → 10.32 s (−9%), peak RSS 50 MiB → 50 MiB.make verifyandfensu checkpass.