Repository navigation
perf(parser): send tokens no lexer rewrite applies to straight to emission - #3105
Merged
Merged
Conversation
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ssion `TokenIter::next` runs every token through the chain of rewrites that reproduce beancount's lexing rules (mid-line comment markers, stray `\r` trivia, lone capitals glued to a run), each step testing the token before finding nothing to do. A token none of the steps can touch now goes straight to emission (`emit_token`, the old `Ok(token)` arm), and so do blanks with no blank or `\r` after them, for which the stray-`\r` step only records an empty run. `split_comment_start` also decides on the first byte before slicing. `rewrite_free` names the kinds each step asks for; the new `rewrite_free_tokens_lex_as_before` test replays the full chain against the fast path (both lexing paths) on every tracked ledger, every fuzz regression and every three-character string over the bytes the rules key on, and fails when a kind is dropped from the list. `rledger check` on 10k-transaction ledgers: -1.0% to -1.3% instructions. Output is byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
perf/lexer-plain-token
branch
from
November 29, 2026 04:16
9dd4576 to
8134929
Compare
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.
What
TokenIter::next(the lexer wrapper both parse paths use) runs every token through the chain of rewrites that reproduce beancount's lexing rules: mid-line#!/#+/%splits, stray-\rtrivia, the three lone-capital rules, comment-to-line-end, the AST path's blank dropping, then the column-0 arms. Each step tests the token before finding it has nothing to do, and on a clean ledger that is every step for nearly every token.emit_token, which is the oldOk(token)arm moved into a method, unchanged.\rright after them skip the stray-\rstep, which for them only records an empty run (the samestray_cr_failed_untilupdate is made).split_comment_startdecides on the first byte (#/%) before the column test and the slice.Not a second classifier:
rewrite_freeonly lists the token kinds each existing step asks for, and every other token still goes through the full chain. Part of the clean-path work against v0.24.0 (hot spot 2 of the perf review).Numbers
rledger check,instructions:u,profilingprofile with LTO off / 16 CGUs,BEANCOUNT_DISABLE_LOAD_CACHE=1, 10k transactions:emit_tokenis#[inline(always)](withallow(clippy::inline_always)): a plain#[inline]stayed out of line and kept only a third of the gain.The perf review's estimate for the lexer (+40M) counted what moved from
lossless_kind_tokensintoTokenIter::next. Against a v0.24.0 build with the same profile, the wrapper's own cost grew by about 22M onsimple; this takes back about 6M of that. The rest is per-call overhead spread across the wrapper, not any one rewrite.No output change
rewrite_free_tokens_lex_as_before: with a test-only switch (test_counters::SLOW_PATH_ONLY) the fast paths are skipped, and the token streams oftokenizeandtokenize_losslessmust be equal both ways on every tracked ledger, every fuzz regression, and every three-character string over 22 fragments (' ',\t,\r,\r\n,A,#,%,!,+,:,;,*,&,",{,-, BOM,USD, ...) after five line prefixes. Mutation-checked: droppingFlagfromrewrite_freefails it at once.mainon 45,182 inputs (pinned fuzz corpus, compat corpus, tracked ledgers):parse_error_lines --jsonlandsemantic_snapshot.scripts/compat-beancount-oracle-drift.py: 123,007 compared, tokens and errors all agree.compat-parse-error-parity.py --checkandcompat-semantic-parity.py --check: no regressions.cargo test -p rustledger-parser -p rustledger-loader(includingbc_lexer_driftand thefuzz_green_eq_redcorpus test); clippy-D warnings.🤖 Generated with Claude Code