Ledgeline performance baseline
These are the numbers PERF-1 … PERF-5 are measured against. They were recorded before any Phase 6 optimization landed, so they are the “before” that every later run diffs against.
“The code review” below means the July 2026 code review that produced the PERF-* findings and the Phase 6 plan. It was a maintainer’s working list and is not part of this repository.
| Date | 2026-07-27 |
| Machine | Apple M5 Max, 18 cores, 64 GB, macOS 26.5.2 (25F84) |
| Toolchain | rustc 1.97.1 (8bab26f4f 2026-07-14), cargo 1.97.1, from the flake dev shell |
| hledger | 1.52 (corpus validation only) |
| Profile | cargo bench → the bench profile, which inherits the workspace [profile.release]: opt-level = 3, lto = true, codegen-units = 1 |
| Corpus | benches/corpus.rs v1, generated at 5k / 50k / 200k transactions |
| Criterion | 0.7.0; heavy groups run sample_size = 10, warm_up = 0.5 s, measurement = 5 s |
| Baseline name | saved as phase6 (--save-baseline phase6) |
1. Reproducing this
# Generate the corpus and prove hledger accepts it (strict mode).
nix develop -c ./scripts/gen-perf-journals.sh 5000 50000 200000
# or: just perf-corpus 5000 50000 200000
# Run every bench at every size and record a named baseline.
nix develop -c just bench-save phase6
# After a change, re-run and get a per-bench delta.
nix develop -c just bench-compare phase6
Default cargo bench covers 5k and 50k only. Adding 200k roughly doubles the
run. Opt in with the LEDGELINE_BENCH_SIZES environment variable, which takes a
comma-separated list of transaction counts:
LEDGELINE_BENCH_SIZES=5000,50000,200000 nix develop -c cargo bench -p ledgeline-core
LEDGELINE_BENCH_SIZES=200000 nix develop -c cargo bench -p ledgeline-core -- 'reports/net_worth'
The run that produced this document (all three sizes, 81 benchmarks) took ~14 minutes of wall-clock time, of which roughly 6 were the 5k pass. A default two-size run is about 8 minutes.
Peak RSS
Criterion measures time, not memory, and PERF-1 is a memory finding. Use the
load_rss example, which builds exactly what Snapshot::from_journal holds and
keeps it alive until the process exits:
nix develop -c just perf-rss 200000
# or by hand:
nix develop -c cargo build --release -p ledgeline-core --example load_rss
/usr/bin/time -l ./target/release/examples/load_rss 200000 --stage snapshot
--stage is one of text | parse | clone | value | snapshot | bytes. The first
five are nested, so subtracting consecutive peaks shows which stage added the
memory. bytes is separate and models the PERF-1 target state (journal + serialized bytes,
no Value tree, no journal clone).
On macOS /usr/bin/time -l reports maximum resident set size in bytes. On
Linux use /usr/bin/time -v, which reports KB.
2. The corpus
crates/ledgeline-core/benches/corpus.rs generates the corpus and caches it in
target/perf/. That directory is gitignored, because 26 MB of synthetic journal
does not belong in git.
Determinism. generate(n) is a pure function of n. The only entropy source
is a SplitMix64 seeded from a compile-time constant and advanced in a fixed
order. There is no clock, no environment read, no HashMap iteration, and no f64
anywhere in the money or date math. Deleting and regenerating all three
journals reproduces identical SHA-256 digests.
65ba2490fe8ac04e2cd2f08d11b95eca465cd96f22bd866d00c8c5e943acee0e synthetic-v1-200000.journal
f411fd8d8b8ce7b9a73a4e7f487cdb2efdd7401c984e65473406c8506456147e synthetic-v1-5000.journal
7cb9a3cb7847c13ac80e6cf46da6a2483d91b221253612e386b756c5ff2dacc6 synthetic-v1-50000.journal
The filename includes CORPUS_VERSION. Any change to the emitted shape must
bump it, so a stale cache cannot hide the change.
Validity. All three pass hledger -f <file> check -s in strict mode. That
means every transaction balances, every balance assertion evaluates, every account and
commodity is declared, and every date is a real calendar date. Phase 2 added the
same strictness to the engine, and the generator’s balance assertions are
computed from an exact i64-cents running balance rather than from rounded
display text.
| Generated | The code review’s stated shape | |
|---|---|---|
| Declared accounts | 300 | 300 |
| Accounts actually used | 248 | 243 |
| Commodities | 5 ($, EUR, AAPL, VTI, GLD) | 5 |
P directives | 1,488 | 1,488 |
| Date span | 1996-01-01 → 2025-12-31 (10,958 days) | 30 years |
| Postings / txn | 2.20 (443,440 at 200k) | ~2.1 (420k at 200k) |
Cost-annotated amounts (@/@@) | 18,203 at 200k | ~18,530 implied |
Total PriceDirectives after inference | 19,691 at 200k | 20,018 |
| Source size 5k / 50k / 200k | 0.70 / 6.58 / 26.18 MB | 0.74 / 7.0 / 27.7 MB |
The corpus also includes these, because the engine paths under test need them: ~ monthly and
~ yearly periodic rules (so budget_report has goals), unbalanced (a) and
balanced-virtual [a]/[b] postings, transaction and posting comments, type:
tags on roots and cash accounts, all three statuses, elided amounts, digit-grouped
$1,234.56 and comma-decimal 1.234,56 EUR styles.
Where the shape differs. The corpus is ~5% smaller per transaction than the code review’s and has ~5% more postings per transaction. Both differences are small, and the timings below track the document closely enough that the journal shape does not explain any of the discrepancies in §4.
3. Baseline numbers
Times are criterion’s point estimate (the middle of the [lo est hi] triple).
parse
| Bench | 5k | 50k | 200k |
|---|---|---|---|
parse/parse_journal | 6.43 ms | 63.0 ms | 253 ms |
wire / snapshot: PERF-1, PERF-1b
| Bench | 5k | 50k | 200k |
|---|---|---|---|
wire/journal_to_value | 27.8 ms | 287 ms | 1,107 ms |
wire/serialize_bytes (the PERF-1 replacement) | 13.2 ms | 138 ms | 533 ms |
wire/clone_value (per request today) | 17.5 ms | 177 ms | 691 ms |
wire/to_string (per request today) | 5.99 ms | 59.1 ms | 242 ms |
wire/clone_journal (PERF-1b) | 2.07 ms | 20.3 ms | 86.5 ms |
wire/snapshot_from_journal (all of Snapshot::from_journal) | 40.6 ms | 409 ms | 1,696 ms |
aggregate / account types: PERF-5e, PERF-5f
| Bench | 5k | 50k | 200k |
|---|---|---|---|
aggregate/account_totals | 866 µs | 9.03 ms | 43.8 ms |
aggregate/roll_up | 131 µs | 133 µs | 144 µs |
accounts/resolve_account_type_sweep (once per posting) | 660 µs | 6.70 ms | 26.8 ms |
accounts/declared_types (rebuilt per HTTP request) | 2.86 µs | 2.86 µs | 2.85 µs |
prices: PERF-5d
| Bench | 5k | 50k | 200k |
|---|---|---|---|
prices/PriceDb_build | 231 µs | 710 µs | 2.40 ms |
prices/lookup_early_date | 707 ns | 2.43 µs | 8.27 µs |
prices/lookup_late_date | 23.3 ns | 22.7 ns | 23.2 ns |
reports: PERF-5, PERF-5c
| Bench | 5k | 50k | 200k |
|---|---|---|---|
reports/net_worth/count_12 | 11.7 ms | 116 ms | 552 ms |
reports/net_worth/count_24 | 22.5 ms | 237 ms | 1,059 ms |
reports/net_worth/count_60 | 53.3 ms | 571 ms | 2,508 ms |
reports/cash_flow/count_12 | 545 µs | 8.16 ms | 54.5 ms |
reports/cash_flow/count_60 | 2.77 ms | 38.8 ms | 273 ms |
reports/budget/count_12 | 776 µs | 8.01 ms | 56.1 ms |
reports/budget/count_60 | 3.74 ms | 41.0 ms | 272 ms |
reports/balance_sheet | 1.16 ms | 9.99 ms | 45.3 ms |
reports/income_statement | 442 µs | 1.60 ms | 7.47 ms |
reports/subscriptions | 1.43 ms | 15.1 ms | 76.2 ms |
reports/insights | 22.5 ms | 252 ms | 1,197 ms |
Added 2026-11-10 (plan 37), measured later than the rows above on the same machine and corpus:
| Bench | 5k | 50k | 200k |
|---|---|---|---|
reports/saas | 5.21 ms | 31.2 ms | 114 ms |
reports/insights (same run, for comparison) | 16.3 ms | 183 ms | 890 ms |
/api/saas and /api/insights load in parallel, and the startup section’s /api/saas is never the slower of the two.
Plan 38 WP-1 (2026-11-12, same machine and corpus, rustc 1.99.1) landed in two
commits. Output is byte-identical to before; see tests/insights_golden.rs.
The first commit builds one combined PriceDb and one explicit-only PriceDb
per request, down from eight. One chained holdings replay serves both gain
windows instead of four, and the movers probe reuses the windows’
price-independent holdings setup.
The second commit cuts the per-posting work:
- The holdings replay, the sole-symbol facts and
stock_accountswalk only the transactions that post to an account carrying a security (stock_order). That set is built once per request and shared by both windows and the movers probe. - One sole-symbol facts scan, capped at the window end, serves all three holdings reports.
is_iso_coderejects anything that is not three bytes long before its 158-way string match. It runs for every amount, most of them$.add_postingno longer clones the account name per posting.
| Bench | 5k | 50k | 200k |
|---|---|---|---|
reports/insights before WP-1 | 16.6 ms | 197 ms | 916 ms |
| after the first commit | 9.20 ms | 106 ms | 518 ms |
| after the second commit | 4.73 ms | 49.9 ms | 293 ms (−68%) |
That is under the 400 ms gate. The ~270 ms of one 200k request now breaks down like this:
HoldingsInputssetup, ~75 ms: theCurrenciesmoney scan, thestock_orderfilter and the declaration tables. These are the only full-journal passes left on the holdings side.account_totals×4, ~82 ms. The two cumulative ones are ~36 ms each.net_worth×2, ~58 ms.- Price inference and the
PriceDbbuild, ~12 ms. income_statement×2, ~10 ms.- The shared facts scan (~5 ms), the window pair (~11 ms), the movers probe (~11 ms) and the top transactions (~3 ms).
The second commit’s shared-code changes were benched against the commit
before it (reports/, holdings/, aggregate/ and accounts/, at 50k and
200k):
- Holdings:
compute_holdings−53% andholdings_series_*−58% at 200k. account_totals−11% at 200k; cash flow, budget, balance sheet and income statement −2% to −34%.net_worthat 50k read +13–25%, but none of its code changed. The unchanged parent commit re-measured +6–10% against the same baseline, so most of that is machine drift, and any remainder is codegen layout. At 200k it is flat.
If more speed is ever needed, these are the next changes to make:
- Fold the two cumulative
account_totalsand the twonet_worthcalls into one bucketed pass each. Every sum is order-independent, asnet_worth_pricedalready relies on. - Fold the
stock_orderfilter into theCurrenciesscan.
holdings: PERF-5b
| Bench | 5k | 50k | 200k |
|---|---|---|---|
holdings/compute_holdings | 2.18 ms | 25.3 ms | 131 ms |
holdings/holdings_series_12 | 25.3 ms | 297 ms | 1,567 ms |
running: plan 36
Measured 2026-11-09 on the same machine, 200k only
(LEDGELINE_BENCH_SIZES=200000 cargo bench -p ledgeline-core --bench engine -- 'running/').
Not part of the 2026-07-27 baseline run above.
| Bench | 200k |
|---|---|
running/posting_order (once per snapshot, on the first pin) | 5.69 ms |
running/build_leaf (assets:bank:chase:checking) | 5.93 ms |
running/build_assets (assets, the widest pin the corpus has) | 30.9 ms |
A leaf pin costs about what the plan expected. A whole-root pin like assets
costs ~5× that, because it keeps one entry per matching posting. It is built once
per root and kept (LRU of 4), so only the first request pays.
Peak RSS
/usr/bin/time -l, one process per stage, so each row is that stage’s own peak.
| Stage | 5k | 50k | 200k | Δ at 200k |
|---|---|---|---|---|
text: source held | 2.3 MB | 7.9 MB | 26.6 MB | — |
parse: + parsed Journal | 17.0 MB | 149.0 MB | 582.4 MB | +555.8 MB |
clone: + Arc::new(journal.clone()) | 24.6 MB | 220.1 MB | 866.2 MB | +283.8 MB |
value: + /transactions Value | 91.5 MB | 888.3 MB | 3,546.5 MB | +2,680.3 MB |
snapshot: + other 6 wire Values | 96.9 MB | 895.7 MB | 3,563.4 MB | +16.9 MB |
bytes: PERF-1 target state | 42.4 MB | 372.9 MB | 1,478.0 MB | — |
The /transactions payload serializes to 8.60 MB / 86.5 MB / 347.1 MB.
4. Reproducing the code review’s Phase 6 claims
This section checks every Phase 6 claim that has a number against the measurements above. Some of the document’s numbers are HTTP-endpoint latencies; the closest engine bench is named in each case.
Reproduced (within ~20%)
| Code review claim | Doc | Measured | Note |
|---|---|---|---|
parse_journal, 5k | 6 ms | 6.43 ms | |
parse_journal, 50k | 65 ms | 63.0 ms | |
parse_journal, 200k | 216 ms | 253 ms | +17%; our corpus has 5.6% more postings |
net_worth at count=12 | 545 ms | 552 ms | |
net_worth at count=60 | 2,547 ms | 2,508 ms | linear scaling in bucket count confirmed (12→24→60 is 552 / 1,059 / 2,508 ms; slope 41.8 ms per bucket, intercept ~50 ms) |
/api/holdings/series 1,599 ms | 1,599 ms | 1,567 ms | holdings_series_12 |
/api/insights 1,066 ms | 1,066 ms | 1,197 ms | +12% |
journal.clone() 78 ms | 78 ms | 86.5 ms | |
| serde re-walk 269 ms/request | 269 ms | 242 ms | wire/to_string |
| Peak RSS 5k | 94 MB | 96.9 MB | |
| Peak RSS 50k | 869 MB | 895.7 MB | |
| Peak RSS 200k | 3,447 MB | 3,563.4 MB | |
| RSS: source text held | 29 MB | 26.6 MB | |
RSS: parsed Journal | +601 MB | +555.8 MB | |
RSS: journal.clone() | +310 MB | +283.8 MB | |
RSS: /transactions Value | +2,449 MB | +2,680.3 MB | +9% |
PriceDb holds 20,018 directives | 20,018 | 19,691 | corpus shape, −1.6% |
| “Parsing is not the problem” | 1.08 µs/txn | 1.27 µs/txn | parse is 15% of Snapshot::from_journal, so the conclusion holds |
Reproduced in kind, but the magnitude is off
| Code review claim | Doc | Measured | Assessment |
|---|---|---|---|
Snapshot::from_journal, 200k | 1,190 ms | 1,696 ms | +43%. Same at every size (5k 31 → 40.6 ms, 50k 297 → 409 ms), so this is a consistent offset, not noise. The finding is understated. The snapshot build is slower than the document says, and it is still ~85% of startup. Nothing downstream is invalidated. |
wire::journal_to_value | 825 ms | 1,107 ms | +34%, consistent with the above. |
.clone() of the Value tree per request | 342 ms | 691 ms | 2.0×. Only ~6% of that is corpus shape. If the document’s 1,094 ms /transactions latency was built from 342 + 269, the clone half of it is twice as large as stated. Again, PERF-1 is understated, not wrong. |
PriceDb::latest, recent date | 0.004 µs | 0.0232 µs | 5.8×. 4 ns cannot cover a BTreeMap<Commodity, _> lookup plus a date string compare; 23 ns can. The document’s early/late ratio (2,800×) is what the finding depends on, and it holds. We measure 356× at 200k, growing linearly with directive count (30× at 5k, 107× at 50k). PERF-5d’s diagnosis is right; treat its absolute “0.004 µs” as unreliable. |
PriceDb::latest, old date | 11.2 µs | 8.27 µs | −26%, tracks the 1.6% smaller directive count plus the choice of test date. |
Could not reproduce / could not measure
| Claim | Why |
|---|---|
/transactions endpoint 1,094 ms, /api/reports/networth 435 ms, balance sheet 36 ms, /version 1,475 ms under 20 concurrent requests (PERF-3), 4 reload cycles per save (PERF-4), gzip ratio 4.8% (PERF-2), POST /api/transactions 470–880 ms | Out of scope for this baseline. All of them require benching crates/ledgeline-server, which the baseline work did not touch. The engine-side components are covered (net_worth/count_12 = 552 ms vs the 435 ms endpoint; wire/clone_value + wire/to_string = 933 ms of the claimed 1,094 ms /transactions latency). A crates/ledgeline-server/benches/snapshot.rs is still owed; see §6. |
/transactions JSON is 291.7 MB | Measured 347.1 MB. Both the payload and the posting count are ~19% higher here. The ratio of JSON bytes to source bytes (13.3×) is the shape-independent figure. |
“Other 4 wire Values +42 MB” | Measured +16.9 MB, and there are six of them, not four (accountnames, prices, commodities, accounts, diagnostics, version). The difference is immaterial either way. |
Two claims the baseline contradicts
-
PERF-5f (
roll_upclones the accumulator) is too small to matter.aggregate/roll_upis flat in journal size: 131 µs at 5k, 133 µs at 50k, 144 µs at 200k. Its input isaccount_totals’ output, whose size is bounded by the account count (248), not by the transaction count. It is called once per bucket insidenet_worth, so at 60 buckets the entire theoretical win is ~8.6 ms out of 2,508 ms, or 0.3%. The clone-per-addition is real and worth fixing for style, but do not budget optimization time against it and do not expect a measurable delta. -
net_worthis ~95%account_totalsre-scans, which is exactly what PERF-5’s single-pass rewrite targets.account_totalsalone is 43.8 ms at 200k;net_worth/count_12is 552 ms ≈ 12 × 43.8 ms + 26 ms. No other Phase 6 finding has stronger numbers behind it, and they put the fix close to the 50 ms estimate. The three other wastes PERF-5 lists inside the loop (roll_up, the doubleat_depth,remap_account) together account for the remaining ~5%.
Two smaller calibrations for whoever picks up PERF-5e:
accounts/declared_types is 2.9 µs, so “rebuilt on every HTTP request” is true
but costs microseconds. resolve_account_type_sweep is 26.8 ms per full
posting sweep at 200k (60 ns/call), so memoizing it is worth tens of
milliseconds per report, not hundreds.
5. How to compare after a change
# 1. Confirm you are diffing against the same corpus.
shasum -a 256 target/perf/*.journal # must match §2
# 2. Re-run and let criterion do the comparison.
nix develop -c just bench-compare phase6
Criterion prints change: [-x% -y% -z%] (p = …) per bench and labels each
Improved / Regressed / No change. With sample_size = 10 on the heavy
groups it cannot detect a change under about 5%. Every Phase 6 finding claims
3–10×, so that is enough. Do not “improve” a number by regenerating the corpus.
Bumping CORPUS_VERSION invalidates this baseline, and every table above would
have to be re-measured.
Gate on these four benchmarks, because they are the delays a user notices:
| Bench | Baseline (200k) | Target after the fix |
|---|---|---|
wire/snapshot_from_journal | 1,696 ms | ≤ 700 ms (PERF-1) |
reports/net_worth/count_60 | 2,508 ms | ≤ 200 ms, and within 2× of count_12 (PERF-5) |
holdings/holdings_series_12 | 1,567 ms | ≤ 300 ms (PERF-5b) |
reports/insights | 1,197 ms | ≤ 400 ms (PERF-5c); met: 293 ms after plan 38 WP-1, see §3 |
One pair must also converge rather than shrink:
prices/lookup_early_date (8.27 µs) and prices/lookup_late_date (23.2 ns)
should end within an order of magnitude of each other once latest uses
partition_point.
For peak RSS at 200k, 3,563 MB → the bytes stage’s 1,478 MB is the
lowest PERF-1 can reach as currently written. That 1,478 MB includes the
intermediate Vec<WireTransaction> that journal_to_transactions builds before
serialization. Serializing as a stream, or straight from the Journal, would
bring it lower.
6. Known gaps
- No
crates/ledgeline-serverbenches. The code review asks forbenches/snapshot.rswithsnapshot/from_journalandsnapshot/serve_transactions.Snapshotispub(crate), and the server crate was out of scope for the baseline work, sowire/snapshot_from_journalin the core bench replicatesSnapshot::from_journal’s body instead. It is a hand-kept copy. IfSnapshot::from_journalgains or loses a payload, updatesnapshot_payloads()inbenches/engine.rsto match, or the bench no longer measures the real snapshot build and nothing reports it. - No HTTP-level benches, so PERF-2 (ETag/compression/windowing), PERF-3
(
spawn_blockingunder concurrency) and PERF-4 (watcher debounce) have no numbers here at all. They need a server-side harness. - No
parse/includes_200k. The code review asks for it to show thatincludesplitting costs nothing, but the generator emits a single file. Adding it means teaching the generator to shard intoincluded files. - No CI wiring.
nix build .#clippyruns--all-targets, so CI compiles the benches and examples and they cannot fall out of date..#clippy,.#fmtand.#testsall pass with these files present. Nothing runs them or compares baselines, though, because a shared runner would be too noisy for the ~5% resolution above without pinning. Note that Nix flakes only see git-tracked files, sonix build .#clippyfails with “can’t find benchengine” untilcrates/ledgeline-core/benches/is committed. cargo-llvm-covis still absent fromflake.nix(out of scope here), so every coverage claim in the code review remains read-derived.
7. The v2 large-repo corpus (200 commodities, 75 accounts)
Added 2026-08-31. Everything above is v1 and is unchanged. generate(n) is
frozen on the V1 shape, and the three SHA-256s in §2 were re-verified against
the parameterized generator before and after this section was written. If a v1
digest ever changes, §3 is void. Do not reconcile it. Regenerate it.
7.1 Why a second corpus
v1 has five commodities, so every per-commodity cost in the engine is
multiplied by five and disappears into the noise. Several findings are quadratic
or worse in the commodity count, so v1 cannot show them. v2 is the fixture from
the original request: 10k transactions a year for 15 years, ~200 commodities and
75 accounts. Those two limits conflict on purpose. One position account per
(broker × symbol) would create 400 accounts, so 25 commodities share each
brokerage account. That is the only way to get a MixedAmount (BTreeMap<Commodity, Dec>) that is 25 entries deep
per account rather than 1.
v2fx is the same journal with a mesh price graph instead of a $-star.
Three guards in the engine only stop applying on a mesh, so a star-only corpus
would have measured none of them:
| Guard | What disarms it in v2fx |
|---|---|
value_at’s direct-lookup fast path (prices.rs:622) | ~59 of the 200 symbols are quoted in EUR or GBP, so lookup_in misses and graph_at runs |
PriceGraph single-hop chains | GBP is quoted in EUR and CHF in GBP, so reaching $ is a 2- and 3-hop chain |
choose_base’s “fewer than 2 candidates” short-circuit (engine.rs:1298) | three price targets ($, EUR, GBP) and one deliberately unpriceable symbol, so no candidate ever prices everything and every one is scanned |
7.2 The corpus
The same benches/corpus.rs generates it, now parameterized by a Shape.
nix develop -c cargo run --release -p ledgeline-core --example gen_journal -- v2 v2fx v2dfx
3d284ea1c32cd056ea00694e4871944c1a42d542dbba706078cc0655c1cf85ea synthetic-v2-150000.journal
c3398c428a6755e0a8f63b2fa08cc0402108f25a660306dee70daff4bc2bd756 synthetic-v2fx-150000.journal
a32163202ed498d7c637c9133154afa753a2fd46de7da90092b23c64283f47ee synthetic-v2dfx-150000.journal
All three are byte-identical on regeneration and all three pass
hledger -f <file> check -s (hledger 1.52), the same bar §2 holds v1 to.
v2dfx (added 2026-11-12, plan 38 WP-2) is described in §7.6.
| v1 (200k) | v2 | v2fx | v2dfx | |
|---|---|---|---|---|
| Transactions | 200,000 | 150,000 | 150,000 | 150,000 |
| Declared accounts | 300 | 75 | 75 | 75 |
| Accounts used | 248 | 51 | 51 | 51 |
| Commodities declared | 5 | 202 | 204 | 209 |
| Commodities per brokerage account | 1 | 25 | 25 | 25 |
P directives | 1,488 | 36,180 | 36,360 | 41,040 |
| Price graph | $-star | $-star | mesh (2–3 hop chains) | dense mesh (8 currencies, pairwise) |
| Unpriceable symbols | 0 | 0 | 1 | 1 |
| Date span | 30 y | 15 y (2011-01-01 → 2025-12-31) | same | same |
| Postings | 443,440 | 332,451 | 332,447 | 332,868 |
| Cost-annotated amounts | 18,203 | 13,650 | 13,655 | 13,533 |
| Source size | 26.18 MB | 20.32 MB | 20.36 MB | 20.52 MB |
Run the benches against them with LEDGELINE_BENCH_SHAPES, which replaces
LEDGELINE_BENCH_SIZES for non-v1 shapes and leaves the default run untouched:
LEDGELINE_BENCH_SHAPES=v2,v2fx,v2dfx nix develop -c cargo bench -p ledgeline-core
LEDGELINE_BENCH_SHAPES=v2fx@20000 nix develop -c cargo bench -p ledgeline-core -- holdings/
Benchmark ids include the shape (holdings/compute_holdings/v2fx-150k), so a v2
number can never be mistaken for a v1 one or diffed against it.
7.3 What C=200 costs, measured
This compares two engine states on the same corpus, machine and session. “Before” is
the engine as it stood on 2026-08-31 before the four latest_directive_price /
MixedAmount / base_commodity / ValuationMeta fixes, and “after” is with them.
| Bench | before | after | change |
|---|---|---|---|
holdings/holdings_series_60/v2-150k | 902.4 ms | 134.2 ms | −85.1% |
holdings/holdings_series_60/v2fx-150k | 990.8 ms | 209.2 ms | −78.9% |
holdings/holdings_series_12/v2-150k | 274.8 ms | 124.7 ms | −54.6% |
holdings/holdings_series_12/v2fx-150k | 343.4 ms | 180.3 ms | −47.5% |
holdings/compute_holdings/v2-150k | 131.3 ms | 123.2 ms | −6.2% |
holdings/compute_holdings/v2fx-150k | 192.8 ms | 171.5 ms | −11.0% |
reports/subscriptions/v2-150k | 59.6 ms | 50.8 ms | −14.8% |
reports/balance_sheet/v2-150k | 31.5 ms | 28.7 ms | −8.9% |
aggregate/account_totals/v2-150k | 31.7 ms | 29.9 ms | −5.8% |
aggregate/roll_up/v2-150k | 138 µs | 130 µs | −6.3% |
The same fixes are worth 1–3% on v1 at 200k and 6.7× on v2. That gap is why
this corpus exists. latest_directive_price’s raw-slice scan cost
O(dates × commodities × directives), and v1 holds that to 12 × 5 × 1,488 while
v2 makes it 60 × 200 × 36,180.
The scaling shows it more clearly. PERF-5b is gated on series_60 / series_12:
| before | after | |
|---|---|---|
| v2 | 902.4 / 274.8 = 3.28× | 134.2 / 124.7 = 1.08× |
| v2fx | 990.8 / 343.4 = 2.89× | 209.2 / 180.3 = 1.16× |
Before the fix the holdings series still scaled with the point count at C=200.
The cause was not that pool_snapshots had started splitting the replay. The
per-point pricing scan dominated, which hid the fact that it had not. On v1 the
same ratio reads ~1× either way, so v1 could not have told the two apart.
7.4 What v2 answers about the predictions
TODO.md predicted four slow paths. Here is what was
measured for each:
latest_directive_priceholds up. 123 ms percompute_holdingsat 150k/C=200/36,180 directives is 0.82 µs per transaction, against v1’s 0.97 µs at 200k. The 24× directive count and 40× commodity count cost nothing, as expected from anO(log P)index. One residual cost remains. The walk returns early only on a directive priced in the base, so a symbol that is never priced in the base scans its whole in-effect prefix.v2fxhas 59 such symbols and pays 0.60 ms per series point against v2’s 0.20 ms. That 3× per-point cost is entirely this scan. It was measured here but not fixed. Fixed in plan 38 WP-2 (§7.6):v2fx’sholdings_series_60went from 145 ms to 120 ms.value_at’s per-callPriceGraphrebuild was NOT reproduced.reports/balance_sheetis 28.7 ms on the star and 29.2 ms on the mesh (+2%);net_worth,insightsandincome_statementare all within 1%. The graph is built lazily and at most once pervalue_atcall, andreachable’sO(V·E)only costs much when many nodes are reachable. This mesh is a star-of-stars whose chains are 2–3 hops with a handful of reachable nodes, soshortest_pathnever enumerates anything. Testing that finding needs a denser graph.v2fxis a fair mesh but not a dense one, and that is a limitation of this fixture rather than evidence against the finding. Reproduced on the densev2dfxshape and fixed in plan 38 WP-2 (§7.6).choose_base→coverageis confirmed, and it is the mesh’s main cost. Every mesh-related cost shows up inholdings, not in the reports: +39% oncompute_holdings, +45%/+56% on the 12- and 60-point series. v2 has one candidate and short-circuits; v2fx has three and an unpriceable symbol, so no candidate ever prices everything and all three are scanned.pool_snapshotsreplay splitting did NOT happen, and the PERF-5b fix holds at C=200.series_60 / series_12is 1.08× (v2) and 1.16× (v2fx). A split intomin(D, 2A)replays would have putseries_60near 60 ×compute_holdings≈ 7.4 s; it is 134 ms. This was the regression most likely to pass the v1 gate unnoticed, and it is not there.
Two smaller results are worth recording. aggregate/roll_up is 130 µs on v2 against
65 µs on v1. That is the only place the 25-commodities-per-account MixedAmount shows
up as a clean 2×, and it is still microseconds. And prices/lookup_early_date
(28.9 ns) versus lookup_late_date (11.6 ns) stay within 2.5× of each other at
36,180 directives, so PERF-5d’s convergence holds at 24× the directive count.
7.5 Not measured
/api/insights’sPriceDb::builds.prices/PriceDb_buildis 5.70 ms on v2 against 1.69 ms on v1 at 200k. There were eight builds per request; plan 38 WP-1 cut that to two (one combined, one explicit-only), so ~11 ms on v2.
Peak RSS on v2 and the dense price graph used to be listed here. Both are measured now, in §7.6.
7.6 A dense FX graph, and peak RSS (plan 38 WP-2)
Added 2026-11-12. v2fx never ran PriceGraph’s chain search, so the
value_at finding in §7.4 had never been measured. v2dfx (V2_DENSE_FX) is
v2 with a dense many-to-many FX graph built to exercise it:
- Eight currencies quote each other pairwise. That is 28
Ppairs a month. Only EUR is priced in$, and EUR is quoted in every other currency while nothing is quoted in EUR. So no currency reaches$along forward edges, and every currency valuation misses the direct lookup, fails the forward search and falls through to the reverse-edge one. - Two thirds of the symbols are quoted in a mesh currency. Half of those
are also traded in it, paid from the multi-currency EUR wallet, so nothing
ever prices them in
$, not even cost inference. - A tenth of simple expenses are paid in a mesh currency. This means
income_statement_flows, which values every transaction, misses too. - Seven in eight FX legs swap one mesh currency for another. As in
v2fx, the last symbol is never quoted at all.
reports/income_statement_flows is a new bench: one value_at per
transaction’s statement legs.
Before and after. The “before” baseline is criterion’s wp2-before, taken
on b7fa7bf, the commit that added the corpus. “After” is 4fa4852. Both were
run in the same session with LEDGELINE_BENCH_SHAPES=v2,v2fx,v2dfx.
| Bench | v2dfx before | v2dfx after | change |
|---|---|---|---|
reports/income_statement_flows | 2,428 ms | 36.4 ms | −98.5% |
reports/balance_sheet_columns/one_pass_30 | 4,790 ms | 82.3 ms | −98.3% |
reports/balance_sheet_columns/n_calls_30 | 6,885 ms | 2,161 ms | −68.6% |
reports/net_worth/count_12 | 943 ms | 63.4 ms | −93.3% |
reports/net_worth/count_60 | 4,298 ms | 125.9 ms | −97.0% |
reports/insights | 792.7 ms | 479.7 ms | −39.5% |
holdings/compute_holdings | 252.8 ms | 136.3 ms | −46.1% |
holdings/holdings_series_12 | 305.3 ms | 138.1 ms | −54.9% |
holdings/holdings_series_60 | 478.7 ms | 141.0 ms | −70.2% |
reports/balance_sheet, income_statement, cash_flow | 26.7 / 6.6 / 17.8 ms | 27.0 / 6.3 / 15.0 ms | no valuation miss |
Before the fix the dense graph was unusable, not merely slow. Net worth
scaled with the bucket count (943 ms → 4.3 s for 12 → 60 buckets) because every
value_at call rebuilt the graph. It now scales like v2 does (63 → 126 ms).
On the sparse mesh, v2fx, balance_sheet_columns/one_pass_30 went from
193 ms to 79 ms, holdings_series_60 from 145 ms to 120 ms (the
latest_directive_price residual), and income_statement from 6.5 ms to
5.7 ms.
On the $-star, v2, nothing misses a direct price, and an instrumented run
confirmed that balance_sheet_columns never builds a graph. The full run read
+2% to +15% on a few v2 benches, but load average rose from ~4 to ~6 during it.
Three interleaved old/new rounds of prebuilt binaries give these medians: net_worth/count_60 69.3 →
70.6 ms, balance_sheet_columns/one_pass_30 54.6 → 56.9 ms, compute_holdings
59.5 → 60.2 ms. That is +1% to +4% against a ±5% run-to-run spread, which is
noise. One real 2% hit-path cost did turn up along the way, in lookup_in’s
“never priced in this target” check. It now runs only after the newest
in-effect directive has missed, and an A/B then read −1.4%.
What changed (three perf(prices) commits):
- The price graph is indexed and searched breadth-first. The graph keeps
per-node outgoing edge lists, and
shortest_pathis a parent-pointer BFS that visits each node’s edges in hledger’s edge order. That picks the lexicographically smallest shortest chain, which is the one hledger’s exhaustive enumeration returns. A unit test checks this against the old enumeration on 3,000 random dense graphs.reachable(O(V·E)) is gone, because the BFS is O(V+E) on its own. PriceDb::graph_atmemoizes one graph per date. Each graph also memoizes the rates it has resolved. This is the step that removes the sharp slowdown as the bucket count grows. No call site changed signature.- Each commodity’s entry records every target it is ever priced in.
lookup_inreturns at once for a pair that is never priced, andlatest_directive_priceno longer walks a symbol’s whole prefix when the base can never appear in it.
Identity. Pretty-Debug captures were taken before the change and
compared after each commit: net worth, holdings and holdings series, other
holdings and their series, grouped balance sheet, grouped income statement,
flows, insights, SaaS, balance-sheet columns, income-statement columns and a
projection. Each was captured at two dates and four valuation targets. The
inputs were all 123 parseable fixture journals plus v1-5k, v2, v2fx and
v2dfx. All 127 captures are byte-identical. The full capture over v2 took
462 s before and 10.5 s after. Most of the difference is
income_statement_grouped with a value_in other than the base, which ran
64 s per call.
Peak RSS (just perf-rss <shape>, macOS /usr/bin/time -l, MB):
| Stage | v2 | v2fx | v2dfx |
|---|---|---|---|
| text | 21.7 | 21.8 | 21.9 |
parse (+ Journal) | 434.6 | 434.6 | 436.3 |
clone (+ Arc<Journal> clone) | 658.1 | 658.2 | 661.5 |
value (+ /transactions Value) | 2,648.9 | 2,649.0 | 2,650.1 |
snapshot (+ 6 other Values) | 2,777.0 | 2,784.6 | 2,794.5 |
| bytes (PERF-1 target) | 1,116.4 | 1,117.1 | 1,118.7 |
The price graph does not show up in memory use. The three shapes are within 2 MB
of each other at every stage, because what is resident is the journal and its
wire forms, not the prices. WP-2 does not change these numbers, because load_rss
runs no report. The graph memo holds at most 64 dates per PriceDb, and each
PriceDb lives for one request.
8. Desktop launch and scroll at 200k (plan 26 B5)
Everything above measures the engine in isolation. This section measures what a person waits for: the desktop app opening a 200k-transaction journal, the first rows appearing, and a hard scroll through them.
8.1 The probe
The probe is a dev tool that does nothing unless you enable it. When LEDGELINE_PERF names a script, the
GUI (mod perf in crates/ledgeline-shell/src/gui.rs) injects it into the
WebView and prints every message it posts back as
PERF js <ms since launch> <json>, plus its own milestones as
PERF rust <label> <ms since launch> (journal_loaded, window_built,
webview_built). A {"ev":"scroll_done"} message ends the process.
scripts/perf/probe.js reports dom_content_loaded, every API request made
before the first rows (fetch, with its duration), data_on_screen (the first
frame committed with REAL rows; the windowed table’s skeleton rows do not
count), and, after a 300-frame scroll at 120 px/frame, scroll_stats: frame
interval, dropped frames (> 1.5 × the median interval), forced-layout cost, and
how many frames still showed a skeleton. It switches the journal to
?preset=all first, because the synthetic corpus ends 2025-12-31 and the
default last-90-days view would be empty.
scripts/perf/run-probe.sh runs it end to end. It launches the app with
HOME pointed at a scratch directory (your real preferences and recents are
never touched), samples footprint for the ledgeline process and the newest
com.apple.WebKit.WebContent process while the probe holds the window open
after its scroll, and prints the PERF lines.
just perf-probe # generates the corpus if missing, builds, runs
# or by hand:
cargo run --release -p ledgeline-core --example gen_journal -- 200000
(cd web && bun run build) && cargo build --release -p ledgeline
scripts/perf/run-probe.sh target/perf/synthetic-v1-200000.journal
# LEDGELINE_BIN=<other binary> measures another build with the same probe.
The window must be visible and frontmost. WebKit throttles requestAnimationFrame
for an occluded window, which shows up as a 33 ms frame interval.
8.2 Before and after
Measured 2026-10-17 on an Apple M5 Max, 18 cores, 64 GB, macOS 27.0.1, both
builds --release, same machine, same corpus, same probe. “Before” is
2e95016 (the last commit before B3) with the probe hook applied; “after” is
B5. Times are milliseconds since launch, medians of 2 (before) and 3 (after)
runs.
Before (SPA downloads /transactions) | After (windowed /api/journal/*) | |
|---|---|---|
journal_loaded (parse + editor + snapshot) | 817 | 525 |
dom_content_loaded | 1,086 | 808 |
First rows on screen (data_on_screen) | 4,250 | 1,011 |
| Scroll frame interval (median / p95) | 17 / ~17 ms | 17 / ~17 ms |
| Dropped frames / 300 | 0 | 0 |
| WebContent footprint | 2.7–3.5 GB | 144–185 MB |
ledgeline footprint | 1.08 GB | ~690 MB |
The 2026-10-16 baseline in plan 26 (first rows ~4.6 s, WebContent ~3.1 GB, ledgeline ~1.0 GB) agrees with the “before” column. Plan 26’s targets are met: first rows well under 1.5 s, WebContent under 500 MB, and no scroll regression.
8.3 Where the launch time goes now
From dom_content_loaded, the SPA asks for /api/journal (one small cached
body), then the first 200-row block and the summary in parallel. The block is
~80 ms; the rest is SvelteKit hydrating and the first paint.
The first block embeds each row’s check findings, so it needs the whole problem list, which is the slowest thing a fresh snapshot computes. Three changes keep that off the critical path:
- Prewarm. Every snapshot starts a background thread
(
ViewCache::warmed) that builds, in order, the display order, the problem list for the server’s date, the sign conventions, the declared styles and the search text. It does this while the WebView is still being created. A request that races a step shares itsOnceLock. - Parallel diagnostics. The holdings pass behind the stock findings
(~210 ms) runs beside the balance/assertion checks (~125 ms) inside
engine_findings, and the local rules run beside both. - Account names deduplicated first.
journal_to_accountnamesexpanded every POSTING’s ancestors (1.5 M strings at 200k); it now expands the few hundred distinct accounts. Account classification went from 145 ms to 32 ms, and the snapshot build, which lists account names twice, got faster with it.
Cold costs at 200k, release build, for reference (/transactions is now built
on first request only, so an SPA session never pays it):
| Derivation (once per snapshot) | ms |
|---|---|
| Display order (sort) | 4 |
| Account classes | 32 |
| Engine findings (parallel) | 195 |
| Local check rules | 67 |
| Sign conventions | 30 |
| Search text (haystacks) | 109 |
| Request, warm | ms |
|---|---|
rows (200 rows, 144 KB) | < 1 |
summary, whole journal | 70–78 |
chart, whole journal (pie / monthly line) | 113 / 133 |
| filter with a query | ~2 (cached search text) |
/transactions, first request | ~950 (334 MB body) |
9. Revenue and expense recognition at 200k (plan 45)
Measured 2026-11-18 on the same machine (Apple M5 Max, 18 cores, macOS 27.2.1), rustc 1.99.1, release profile, under a background load of about 2.5–3. The corpus is the v1 200k journal plus what benches/accrual.rs adds to it: 5,000 deferred-revenue contracts, their rules in a recognition file, and about half of each schedule’s periods posted. That makes 241,741 transactions, 5,000 schedules, 36,741 posted entries and 38,707 entries due on 2026-11-17.
LEDGELINE_BENCH_SIZES=200000 nix develop -c cargo bench -p ledgeline-core --bench accrual
| Bench | 200k | Target | What it is |
|---|---|---|---|
accrual/index_with_roles | 12.8 ms | < 15 ms | The recognition index from a snapshot’s cached account roles: what a request pays |
accrual/index | 35.5 ms | — | The same, also working out the roles (once per snapshot) |
accrual/book_parse | 13.7 ms | < 15 ms | Parsing the 5,000-schedule recognition file, cached by revision |
accrual/due | 3.53 ms | < 5 ms | Every due occurrence as of today |
accrual/ties | 2.73 ms | < 5 ms | Month-end deferred balances against the schedules |
accrual/schedule_build_5k | 30.7 ms | — | Building 5,000 schedules and their rules |
accrual/group_rows | 840 µs | < 2 ms | Collapsing a filter result’s posted entries into month rows |
accrual/post_5k | 548 ms | < 600 ms | 5,000 entries through one add_transactions: format, place by date, one reparse |
The index target was 10 ms and was moved to 15 ms (plan 45, Performance). Reading every posting of a 200k journal costs about 8 ms, so the scan (across up to 8 threads) and its merge land at 12–13 ms.
9.1 Invoice matching: Link and Link all
crates/ledgeline-server/tests/accrual_link_timing.rs times what the client waits for after a click: the write, then the reads that follow it (/api/journal, the status for the badge, and the settlements list). It appends synthetic receivable pairs to the 200k accrual corpus, all clear, because the corpus has none:
cargo test --release -p ledgeline --test accrual_link_timing -- --ignored --nocapture --test-threads=1
| Action | Write | Total, with the reads after it |
|---|---|---|
| One Link | 0.99–1.00 s | 1.16–1.18 s |
| 25 Links, one at a time (how Link all worked before) | — | 29.1 s |
| Link all of 25 | 1.15 s | 1.30 s |
| Link all of 60 | 1.35 s | 1.50 s |
A single link’s write is almost entirely the cost every journal edit pays at this size: the editor’s reparse after the edit (~390 ms), the 36 MB save (~125 ms) and the new snapshot (~360 ms). Two changes brought it here:
- an accrual write runs on a copy of the bound editor instead of parsing the journal again before it and re-opening it from disk after it (1.75 s → 1.0 s);
- Link all is one batch: every pair checked first, then one reparse and one save. The candidates and fingerprints are read once per batch rather than once per pair.
Each re-read after a write costs about 90 ms (/api/accrual) and 70–90 ms (/api/settlements).