Repository navigation
perf(parser): skip the defect checks a clean posting or metadata line cannot fail - #3106
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! |
… cannot fail Since #2802 every posting and metadata line is flattened and checked against beancount's grammar, and every metadata value against the expression check, on clean files too. - `first_posting_defect` returns at once for the shapes nearly every posting has (an account; a signed amount; a `{...}` cost of amounts, dates and labels; an `@` / `@@` price; currencies of two or more letters), and `MetaCheck::line` for `key: value` with one plain value. Any other shape takes the full rule; in debug builds the full rule is replayed on every shortcut line and must agree. - `report_duplicate_metadata` tests `holds_an_invalid_token` (a walk of the whole transaction) only once it has found a repeat, returns at once on an owner with too few keys to repeat one, and keeps the keys in a fixed buffer instead of a vector per owner. - `node_content_span` finds the first content token on the green tree instead of building red nodes (debug-asserted equal to the red walk). `rledger check` on 10k-transaction ledgers: -3.3% to -4.7% instructions, -6.8% on a metadata-heavy one. Errors and directives are byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
perf/cst-defect-fastpath
branch
from
November 29, 2026 04:16
b87760c to
4925b11
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
Since #2802 (and #2893 for repeated metadata), every posting line and every metadata line of every transaction is flattened and checked against beancount's grammar, on clean files too. That is the largest piece of the clean-path regression in
parser::cst::convert(hot spot 1 of the perf review). This takes the clean lines off it without changing what is reported:first_posting_defectreturns at once for the shapes nearly every posting has: an account, optionally a signednumber currency, a{...}/{{...}}cost whose components are amounts, dates or labels, and an@/@@price, with every currency two or more letters (is_plain_posting). The rules give no defect on those shapes (no optflag,incomplete_amount,cost_complist, price, end of line, no glued one-letter currency, no{#). Every other shape takes the full rule, andposting_builder_errorstill runs on every cost or price.MetaCheck::linereturns at once forkey: valuewith one string / account / date / tag / boolean /NULL/ 2+-letter currency (is_plain_meta_line). Those have no grammar defect and no expression value, so the check had nothing to report.report_duplicate_metadata):holds_an_invalid_token(a walk of the whole transaction) runs only once a repeat is found; an owner with too fewMETA_ENTRYchildren to repeat a key returns at once; the keys seen live in a fixed[&str; 16]instead of aVecper owner (the set fallback past 16 keys is unchanged).node_content_span(every directive, in the span fixup) finds the first non-trivia token by walking green children instead ofdescendants_with_tokens()on the red tree.Not a second grammar: the shortcuts only name shapes, and every shortcut line is checked against the full rule by a
debug_assert!in the same function, so every debug test run replays it.node_content_spanlikewise debug-asserts the red walk's answer.Numbers
rledger check,instructions:u,profilingprofile with LTO off / 16 CGUs,BEANCOUNT_DISABLE_LOAD_CACHE=1, 10k transactions:Per item on
simple/ metadata-heavy: duplicate-metadata reorder plus early return ~-15M / -15M, plain postings ~-6M / -6M (more on cost/price ledgers), plain metadata lines ~0 / -35M, fixed key buffer ~0 / -13M,node_content_span~-3M.No output change
mainon 45,182 inputs (the pinnedfuzz_parse+fuzz_green_eq_redcorpus, the compat corpus, every tracked ledger, the profiling workloads):parse_error_lines --jsonlandsemantic_snapshot(tempdir names normalized).parse_error_linesandsemantic_snapshotbuilt withdebug-assertions = true: no assertion fires (each shortcut line is replayed against the full rule, and the green first-token walk against the red one).scripts/compat-beancount-oracle-drift.py: 123,007 compared, all agree.compat-parse-error-parity.py --checkandcompat-semantic-parity.py --check: no regressions.cargo test -p rustledger-parser -p rustledger-loader(debug, so every shortcut is replayed), plustest_plain_line_shortcuts_take_the_common_shapes, which pins the shapes taken and refused. Clippy-D warnings.Touches
cst/convert.rsin four small, local places (MetaCheck::line,node_content_span,report_duplicate_metadata); the rest is incst/directive_header.rs.🤖 Generated with Claude Code