Skip to content

perf(parser): green posting flags + metadata conversion (PR2) - #1595

Merged
robcohen merged 2 commits into
mainfrom
perf/green-posting-flags-meta
Jun 25, 2026
Merged

robcohen merged 2 commits into
mainfrom
perf/green-posting-flags-meta

Conversation

@robcohen

@robcohen robcohen commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What

PR 2 of the lossless-CST-tax removal. Extends the green transaction conversion (shipped in #1594, −16% load) to posting flags and metadata (per-posting and transaction-level), shrinking the set of transactions that fall back to the red path.

After #1594 the green path bailed to red on flags/metadata. Now it handles them, so the only remaining fallbacks are arithmetic/multi-amount postings, direct-child comments, and the deprecated | — all genuinely rarer shapes.

How — same proven pattern (walk green, reuse text parsers, oracle + fuzz)

  • meta_value — typed MetaValue from a META_ENTRY green node, mirroring meta_value_from_entry exactly: priority string > number/amount > date > account > currency > bool > tag/link > none, with the same present-but-unparseable fall-through (a malformed string falls through to number, etc.). Reuses the shared number_meta_value (Int-vs-Number discriminator) and the minus-sign rule.
  • convert_meta_entries — META_ENTRY children → Metadata, used for both per-posting and transaction-level metadata.
  • Posting flag — first non-whitespace token before the account, via posting_flag_char matching PostingFlag::cast + flag_char_from_posting (note: posting flags exclude txn, unlike transaction flags).

Verification

  • 284 parser + 57 integration tests pass; clippy --all-targets -D warnings clean.
  • parse_green_eq_red_corpus extended: all 13 MetaValue types (string / int / negative-int / decimal / amount / date / account / currency / TRUE / FALSE / tag / link / none), posting-flag variants (!, *, #, letter), transaction-level metadata, and flag+cost+price+meta combined — all byte-identical to red.
  • The fuzz_green_eq_red differential fuzz target (from perf(parser): green-tree transaction conversion with red fallback (-16% load) #1594) now also exercises these paths.

Performance note

The synthetic profiling workload has no flags/metadata, so its −16% (from #1594) is unchanged — those transactions were already green. This PR's value is coverage: real ledgers with posting metadata / flags now get the green path instead of red fallback. A metadata-heavy workload measurement is added below.

🤖 Generated with Claude Code


Measured win on a metadata-heavy workload

10k transactions, each with a transaction-level meta key + a posting-level meta key (the shape real ledgers use). On #1594 every such posting fell back to red; now it's green:

#1594 base (meta -> red fallback) = 1,241,834,150
this branch (meta green)          = 1,039,533,860
delta                             =  -202,300,290  (-16.3%)

So this is more than coverage — it's a −16.3% load reduction on ledgers that use metadata, on top of #1594's −16% for plain transactions.

Extends the green conversion path to posting flags and metadata, shrinking the
red fallback set:
- meta_value: typed MetaValue from a META_ENTRY green node (string > number/
  amount > date > account > currency > bool > tag/link > none, with the same
  present-but-unparseable fall-through as red), reusing number_meta_value.
- convert_meta_entries: META_ENTRY children -> Metadata, used for BOTH
  per-posting and transaction-level metadata.
- convert_simple_posting: posting flag (first non-ws token before account, via
  posting_flag_char matching PostingFlag::cast/flag_char_from_posting) + per-
  posting metadata. convert_transaction: transaction-level metadata.

Now bails to red only on arithmetic/multi-amount postings + direct-child
comments + deprecated pipe. parse_green_eq_red_corpus extended with all 13
MetaValue types, posting-flag variants, and flag+cost+price+meta combined;
green byte-identical to red. clippy --all-targets clean, 284 tests.
@robcohen
robcohen requested a review from a team as a code owner June 25, 2026 16:56
Copilot AI review requested due to automatic review settings June 25, 2026 16:56
@codecov

codecov Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56098% with 3 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.1ms ± 0.5ms 23.6 MB
beancount 870.3ms ± 8.8ms 50.7 MB
Comparison 27.1x faster 2.1x less

vs main branch (2026-06-25)

Metric main this PR Change
Time 37.4ms 32.1ms -14.2% 🟢
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

Extends the parser’s “green-tree” transaction conversion path (cst/green.rs) to handle posting flags and metadata (both transaction-level and per-posting), further reducing cases that must fall back to the slower red-node conversion path while preserving byte-identical output equivalence.

Changes:

  • Add green-tree metadata extraction (meta_value, convert_meta_entries) to produce typed MetaValue and Metadata maps consistent with the red conversion logic.
  • Add green-tree posting-flag detection to populate Posting::flag without forcing a red fallback.
  • Expand the parse_green_eq_red_corpus differential test cases to cover posting flags and all supported metadata value types.

Reviewed changes

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

File Description
crates/rustledger-parser/src/cst/green.rs Implements green-path conversion for posting flags + directive/posting metadata; updates green-vs-red equivalence corpus.
crates/rustledger-parser/src/cst/convert.rs Exposes number_meta_value to allow green conversion to reuse the red-path numeric-meta discriminator.

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

@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

Addresses review: convert_simple_posting / convert_transaction collected
metadata via a separate convert_meta_entries pass over node.children() AND the
main loop — a double walk on the hot path even for metadata-free postings.
Replace with meta_entry_kv (key+value for one entry) folded into the existing
loop, so the parent's children are walked once. Update the convert_transaction
doc (it now converts txn-level metadata; no longer a red-fallback trigger).
@robcohen
robcohen merged commit 856bddd into main Jun 25, 2026
50 checks passed
@robcohen
robcohen deleted the perf/green-posting-flags-meta branch June 25, 2026 17:50
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