GitHub
Performance baseline

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.

Date2026-07-27
MachineApple M5 Max, 18 cores, 64 GB, macOS 26.5.2 (25F84)
Toolchainrustc 1.97.1 (8bab26f4f 2026-07-14), cargo 1.97.1, from the flake dev shell
hledger1.52 (corpus validation only)
Profilecargo bench → the bench profile, which inherits the workspace [profile.release]: opt-level = 3, lto = true, codegen-units = 1
Corpusbenches/corpus.rs v1, generated at 5k / 50k / 200k transactions
Criterion0.7.0; heavy groups run sample_size = 10, warm_up = 0.5 s, measurement = 5 s
Baseline namesaved 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.

GeneratedThe code review’s stated shape
Declared accounts300300
Accounts actually used248243
Commodities5 ($, EUR, AAPL, VTI, GLD)5
P directives1,4881,488
Date span1996-01-01 → 2025-12-31 (10,958 days)30 years
Postings / txn2.20 (443,440 at 200k)~2.1 (420k at 200k)
Cost-annotated amounts (@/@@)18,203 at 200k~18,530 implied
Total PriceDirectives after inference19,691 at 200k20,018
Source size 5k / 50k / 200k0.70 / 6.58 / 26.18 MB0.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

Bench5k50k200k
parse/parse_journal6.43 ms63.0 ms253 ms

wire / snapshot: PERF-1, PERF-1b

Bench5k50k200k
wire/journal_to_value27.8 ms287 ms1,107 ms
wire/serialize_bytes (the PERF-1 replacement)13.2 ms138 ms533 ms
wire/clone_value (per request today)17.5 ms177 ms691 ms
wire/to_string (per request today)5.99 ms59.1 ms242 ms
wire/clone_journal (PERF-1b)2.07 ms20.3 ms86.5 ms
wire/snapshot_from_journal (all of Snapshot::from_journal)40.6 ms409 ms1,696 ms

aggregate / account types: PERF-5e, PERF-5f

Bench5k50k200k
aggregate/account_totals866 µs9.03 ms43.8 ms
aggregate/roll_up131 µs133 µs144 µs
accounts/resolve_account_type_sweep (once per posting)660 µs6.70 ms26.8 ms
accounts/declared_types (rebuilt per HTTP request)2.86 µs2.86 µs2.85 µs

prices: PERF-5d

Bench5k50k200k
prices/PriceDb_build231 µs710 µs2.40 ms
prices/lookup_early_date707 ns2.43 µs8.27 µs
prices/lookup_late_date23.3 ns22.7 ns23.2 ns

reports: PERF-5, PERF-5c

Bench5k50k200k
reports/net_worth/count_1211.7 ms116 ms552 ms
reports/net_worth/count_2422.5 ms237 ms1,059 ms
reports/net_worth/count_6053.3 ms571 ms2,508 ms
reports/cash_flow/count_12545 µs8.16 ms54.5 ms
reports/cash_flow/count_602.77 ms38.8 ms273 ms
reports/budget/count_12776 µs8.01 ms56.1 ms
reports/budget/count_603.74 ms41.0 ms272 ms
reports/balance_sheet1.16 ms9.99 ms45.3 ms
reports/income_statement442 µs1.60 ms7.47 ms
reports/subscriptions1.43 ms15.1 ms76.2 ms
reports/insights22.5 ms252 ms1,197 ms

Added 2026-11-10 (plan 37), measured later than the rows above on the same machine and corpus:

Bench5k50k200k
reports/saas5.21 ms31.2 ms114 ms
reports/insights (same run, for comparison)16.3 ms183 ms890 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:

Bench5k50k200k
reports/insights before WP-116.6 ms197 ms916 ms
after the first commit9.20 ms106 ms518 ms
after the second commit4.73 ms49.9 ms293 ms (−68%)

That is under the 400 ms gate. The ~270 ms of one 200k request now breaks down like this:

The second commit’s shared-code changes were benched against the commit before it (reports/, holdings/, aggregate/ and accounts/, at 50k and 200k):

If more speed is ever needed, these are the next changes to make:

holdings: PERF-5b

Bench5k50k200k
holdings/compute_holdings2.18 ms25.3 ms131 ms
holdings/holdings_series_1225.3 ms297 ms1,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.

Bench200k
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.

Stage5k50k200kΔ at 200k
text: source held2.3 MB7.9 MB26.6 MB—
parse: + parsed Journal17.0 MB149.0 MB582.4 MB+555.8 MB
clone: + Arc::new(journal.clone())24.6 MB220.1 MB866.2 MB+283.8 MB
value: + /transactions Value91.5 MB888.3 MB3,546.5 MB+2,680.3 MB
snapshot: + other 6 wire Values96.9 MB895.7 MB3,563.4 MB+16.9 MB
bytes: PERF-1 target state42.4 MB372.9 MB1,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 claimDocMeasuredNote
parse_journal, 5k6 ms6.43 ms
parse_journal, 50k65 ms63.0 ms
parse_journal, 200k216 ms253 ms+17%; our corpus has 5.6% more postings
net_worth at count=12545 ms552 ms
net_worth at count=602,547 ms2,508 mslinear 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 ms1,599 ms1,567 msholdings_series_12
/api/insights 1,066 ms1,066 ms1,197 ms+12%
journal.clone() 78 ms78 ms86.5 ms
serde re-walk 269 ms/request269 ms242 mswire/to_string
Peak RSS 5k94 MB96.9 MB
Peak RSS 50k869 MB895.7 MB
Peak RSS 200k3,447 MB3,563.4 MB
RSS: source text held29 MB26.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 directives20,01819,691corpus shape, −1.6%
“Parsing is not the problem”1.08 µs/txn1.27 µs/txnparse is 15% of Snapshot::from_journal, so the conclusion holds

Reproduced in kind, but the magnitude is off

Code review claimDocMeasuredAssessment
Snapshot::from_journal, 200k1,190 ms1,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_value825 ms1,107 ms+34%, consistent with the above.
.clone() of the Value tree per request342 ms691 ms2.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 date0.004 µs0.0232 µs5.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 date11.2 µs8.27 µs−26%, tracks the 1.6% smaller directive count plus the choice of test date.

Could not reproduce / could not measure

ClaimWhy
/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 msOut 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 MBMeasured 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

  1. PERF-5f (roll_up clones the accumulator) is too small to matter. aggregate/roll_up is flat in journal size: 131 µs at 5k, 133 µs at 50k, 144 µs at 200k. Its input is account_totals’ output, whose size is bounded by the account count (248), not by the transaction count. It is called once per bucket inside net_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.

  2. net_worth is ~95% account_totals re-scans, which is exactly what PERF-5’s single-pass rewrite targets. account_totals alone is 43.8 ms at 200k; net_worth/count_12 is 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 double at_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:

BenchBaseline (200k)Target after the fix
wire/snapshot_from_journal1,696 ms≤ 700 ms (PERF-1)
reports/net_worth/count_602,508 ms≤ 200 ms, and within 2× of count_12 (PERF-5)
holdings/holdings_series_121,567 ms≤ 300 ms (PERF-5b)
reports/insights1,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


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:

GuardWhat 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 chainsGBP 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)v2v2fxv2dfx
Transactions200,000150,000150,000150,000
Declared accounts300757575
Accounts used248515151
Commodities declared5202204209
Commodities per brokerage account1252525
P directives1,48836,18036,36041,040
Price graph$-star$-starmesh (2–3 hop chains)dense mesh (8 currencies, pairwise)
Unpriceable symbols0011
Date span30 y15 y (2011-01-01 → 2025-12-31)samesame
Postings443,440332,451332,447332,868
Cost-annotated amounts18,20313,65013,65513,533
Source size26.18 MB20.32 MB20.36 MB20.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.

Benchbeforeafterchange
holdings/holdings_series_60/v2-150k902.4 ms134.2 ms−85.1%
holdings/holdings_series_60/v2fx-150k990.8 ms209.2 ms−78.9%
holdings/holdings_series_12/v2-150k274.8 ms124.7 ms−54.6%
holdings/holdings_series_12/v2fx-150k343.4 ms180.3 ms−47.5%
holdings/compute_holdings/v2-150k131.3 ms123.2 ms−6.2%
holdings/compute_holdings/v2fx-150k192.8 ms171.5 ms−11.0%
reports/subscriptions/v2-150k59.6 ms50.8 ms−14.8%
reports/balance_sheet/v2-150k31.5 ms28.7 ms−8.9%
aggregate/account_totals/v2-150k31.7 ms29.9 ms−5.8%
aggregate/roll_up/v2-150k138 µs130 µ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:

beforeafter
v2902.4 / 274.8 = 3.28×134.2 / 124.7 = 1.08×
v2fx990.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:

  1. latest_directive_price holds up. 123 ms per compute_holdings at 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 an O(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. v2fx has 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’s holdings_series_60 went from 145 ms to 120 ms.
  2. value_at’s per-call PriceGraph rebuild was NOT reproduced. reports/balance_sheet is 28.7 ms on the star and 29.2 ms on the mesh (+2%); net_worth, insights and income_statement are all within 1%. The graph is built lazily and at most once per value_at call, and reachable’s O(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, so shortest_path never enumerates anything. Testing that finding needs a denser graph. v2fx is 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 dense v2dfx shape and fixed in plan 38 WP-2 (§7.6).
  3. choose_base → coverage is confirmed, and it is the mesh’s main cost. Every mesh-related cost shows up in holdings, not in the reports: +39% on compute_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.
  4. pool_snapshots replay splitting did NOT happen, and the PERF-5b fix holds at C=200. series_60 / series_12 is 1.08× (v2) and 1.16× (v2fx). A split into min(D, 2A) replays would have put series_60 near 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

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:

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.

Benchv2dfx beforev2dfx afterchange
reports/income_statement_flows2,428 ms36.4 ms−98.5%
reports/balance_sheet_columns/one_pass_304,790 ms82.3 ms−98.3%
reports/balance_sheet_columns/n_calls_306,885 ms2,161 ms−68.6%
reports/net_worth/count_12943 ms63.4 ms−93.3%
reports/net_worth/count_604,298 ms125.9 ms−97.0%
reports/insights792.7 ms479.7 ms−39.5%
holdings/compute_holdings252.8 ms136.3 ms−46.1%
holdings/holdings_series_12305.3 ms138.1 ms−54.9%
holdings/holdings_series_60478.7 ms141.0 ms−70.2%
reports/balance_sheet, income_statement, cash_flow26.7 / 6.6 / 17.8 ms27.0 / 6.3 / 15.0 msno 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):

  1. The price graph is indexed and searched breadth-first. The graph keeps per-node outgoing edge lists, and shortest_path is 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.
  2. PriceDb::graph_at memoizes 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.
  3. Each commodity’s entry records every target it is ever priced in. lookup_in returns at once for a pair that is never priced, and latest_directive_price no 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):

Stagev2v2fxv2dfx
text21.721.821.9
parse (+ Journal)434.6434.6436.3
clone (+ Arc<Journal> clone)658.1658.2661.5
value (+ /transactions Value)2,648.92,649.02,650.1
snapshot (+ 6 other Values)2,777.02,784.62,794.5
bytes (PERF-1 target)1,116.41,117.11,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)817525
dom_content_loaded1,086808
First rows on screen (data_on_screen)4,2501,011
Scroll frame interval (median / p95)17 / ~17 ms17 / ~17 ms
Dropped frames / 30000
WebContent footprint2.7–3.5 GB144–185 MB
ledgeline footprint1.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:

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 classes32
Engine findings (parallel)195
Local check rules67
Sign conventions30
Search text (haystacks)109
Request, warmms
rows (200 rows, 144 KB)< 1
summary, whole journal70–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
Bench200kTargetWhat it is
accrual/index_with_roles12.8 ms< 15 msThe recognition index from a snapshot’s cached account roles: what a request pays
accrual/index35.5 ms—The same, also working out the roles (once per snapshot)
accrual/book_parse13.7 ms< 15 msParsing the 5,000-schedule recognition file, cached by revision
accrual/due3.53 ms< 5 msEvery due occurrence as of today
accrual/ties2.73 ms< 5 msMonth-end deferred balances against the schedules
accrual/schedule_build_5k30.7 ms—Building 5,000 schedules and their rules
accrual/group_rows840 µs< 2 msCollapsing a filter result’s posted entries into month rows
accrual/post_5k548 ms< 600 ms5,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.

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
ActionWriteTotal, with the reads after it
One Link0.99–1.00 s1.16–1.18 s
25 Links, one at a time (how Link all worked before)—29.1 s
Link all of 251.15 s1.30 s
Link all of 601.35 s1.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:

Each re-read after a write costs about 90 ms (/api/accrual) and 70–90 ms (/api/settlements).