Skip to content

perf(parser): green walk_top_level pass (PR4) - #1598

Merged
robcohen merged 1 commit into
mainfrom
perf/green-walk-top-level
Jun 25, 2026
Merged

robcohen merged 1 commit into
mainfrom
perf/green-walk-top-level

Conversation

@robcohen

@robcohen robcohen commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What

PR 4 of the lossless-CST-tax removal — greens the last red traversal in the conversion: walk_top_level_once (per-top-level-directive validation). With #1594/#1595 (directive conversion) and #1596 (walk_descendants), this completes the move of the hot parse path off the red SyntaxNode cursor.

Stacked on #1596 — review on top of it; the walk_descendants commits drop out once #1596 merges (I'll rebase onto main then).

How

A green iteration over the root's direct children threads the stripped-frame byte offset (no per-child red-node allocation) and dispatches green re-implementations of all five checks, producing a byte-identical TopLevelWalkResult:

  • indented-directive — first non-trivia token past column 0 → error,
  • custom bare-currency — a CURRENCY not paired as NUMBER CURRENCY after the header,
  • transaction-body catch-all — stray tokens on a body line outside POSTING/META_ENTRY,
  • error-node recovery — per-line classify_recovery_error (BOM / invalid-account / syntax) + secondary BOM,
  • org-section-marker — empty-string comments for *-lines in error nodes.

is_trivia_kind / classify_recovery_error / TopLevelWalkResult are made pub(super) and shared with the red path. Wired behind the existing use_green flag.

Verification

  • 284 + 57 tests pass (errors + comments pinned), clippy --all-targets -D warnings clean.
  • parse_green_eq_red_corpus + fuzz_green_eq_red already compare errors + section-marker comments, so they auto-verify this pass; corpus gains a case per check (indented, tab-indented, custom bare-currency, body catch-all, valid body tag, error-node, section markers + comment).

Performance

Standard 10k-txn workload instruction count added below — the final increment of the green conversion.

🤖 Generated with Claude Code


Measured win on the standard 10k-txn workload

red baseline (pre-green)      = 1,062,145,403
#1596 (+ green walk_descend)  =   802,238,402  (-24.5% vs red)
this (+ green walk_top_level) =   740,408,953  (-30.3% vs red, -7.7% vs #1596)

The final green increment: another −7.7%, for a cumulative −30.3% vs the pre-green red baseline. With all four PRs the parse path is fully off the red SyntaxNode cursor.

@robcohen
robcohen requested a review from a team as a code owner June 25, 2026 18:14
Copilot AI review requested due to automatic review settings June 25, 2026 18:14
@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 35ms ± 0.6ms 24 MB
beancount 749.1ms ± 2.9ms 50.7 MB
Comparison 21.4x faster 2.1x less

vs main branch (2026-06-25)

Metric main this PR Change
Time 37.4ms 35ms -6.4% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the “lossless-CST-tax removal” work by moving the last remaining per-top-level validation traversal (walk_top_level_once) off the red SyntaxNode cursor and onto a green-tree walk, keeping output byte-identical to the red path and gated behind the existing use_green flag.

Changes:

  • Adds green-tree implementations of walk_top_level_once’s five checks (indentation, custom bare-currency, transaction-body catch-all, error-node recovery classification, org section markers) with stripped-frame offset threading.
  • Wires both descendants + top-level passes through green implementations when use_green is enabled, sharing helpers via pub(super) visibility.
  • Extends differential fuzzing and corpus-based tests to also assert account/currency occurrence equivalence (produced by the descendants walk).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
crates/rustledger-parser/src/cst/green.rs Implements green-tree walk_top_level (and includes green descendants walk in this stacked PR) plus corpus extensions to validate byte-identical behavior.
crates/rustledger-parser/src/cst/convert.rs Routes descendants + top-level passes to green versions behind use_green; exposes shared helper/result types to green.rs.
crates/rustledger-parser/fuzz/fuzz_targets/fuzz_green_eq_red.rs Adds equality assertions for account/currency occurrences between green and red parses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Greens the last red traversal in the conversion: walk_top_level_once (per-top-
level-directive validation). A green iteration over the root's direct children
threads the stripped-frame offset and dispatches green re-implementations of all
five checks — indented-directive (column-0), custom bare-currency, transaction-
body catch-all, error-node recovery classification, and org-section-marker
comments — producing a byte-identical TopLevelWalkResult. Wired behind use_green.
Helpers is_trivia_kind / classify_recovery_error / TopLevelWalkResult made
pub(super) and shared with red. Differential (corpus + fuzz, comparing errors +
comments) auto-verifies; corpus gains a case per check. clippy --all-targets
clean, 284 tests.
@robcohen
robcohen force-pushed the perf/green-walk-top-level branch from d173ba1 to b2c0cf4 Compare June 25, 2026 18:19
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.45560% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/green.rs 98.42% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit f34037f into main Jun 25, 2026
50 checks passed
@robcohen
robcohen deleted the perf/green-walk-top-level branch June 25, 2026 18:46
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