Skip to content

perf(profile): profile four workload shapes, not one unrepresentative ledger - #2055

Merged
robcohen merged 2 commits into
mainfrom
perf/profile-workloads
Aug 15, 2026
Merged

robcohen merged 2 commits into
mainfrom
perf/profile-workloads

Conversation

@robcohen

Copy link
Copy Markdown
Member

Phase 0 of the performance work: make the measurement trustworthy before optimizing against it.

No optimization here — this only changes what gets measured. It lands first because the answer it produces contradicts what the old workload implied.

The old workload measured the cheapest path

The sole profiling ledger contained no {, ^ or # anywhere. So it never booked a lot, never matched a reduction, and never entered the three whole-tree error passes in parse_via_cst_inner that those characters gate.

At an identical 2000 transactions:

shape instructions vs simple
simple 119,008,292 1.00×
investment 278,162,145 2.34×
tagged 185,439,627 1.56×
multicurrency 174,720,996 1.47×

The subsystem split doesn't shift — it inverts

subsystem simple investment tagged multicurrency
parser 35.7% 15.1% 28.5% 35.0%
core 7.9% 50.9% 3.6% 4.9%
allocator 30.3% 21.7% 36.1% 33.3%
rowan 22.9% 11.4% 31.0% 24.3%

Read simple alone and the conclusion is "make the parser faster." Read investment and rustledger-core is half the program — the lot matching in Inventory, which simple cannot reach at all.

A plan built on the old workload would have aimed at the wrong subsystem. That is the whole reason this lands before any tuning.

What changed

  • scripts/gen-profile-workload.py — the generator moves out of the workflow heredoc. A profile has to be reproducible locally, and while it lived in the YAML the only way to see what was being measured was to read the workflow, which is how it drifted this far unnoticed.

  • profile.yml — the cachegrind job runs a matrix over all four shapes; both jobs call the script.

  • scripts/check-profile-workloads.sh — asserts the two properties that make these workloads worth anything, neither self-evident from the generator:

    1. each shape loads cleanly — a workload with errors profiles the diagnostic paths, a different program;
    2. each shape still contains the feature it exists for.

    simple is additionally asserted not to grow cost specs, tags or links: its job is to stay the cheap-path floor.

The guard is mutation-checked in both directions. A generator that stops emitting {...} fails the load check; one that drops #tag while still producing a valid ledger — the exact drift that happened here — fails the feature check with exit 1. A guard that can only ever say "ok" would be decoration.

What this surfaced

Worth flagging for the next phase: on investment, imbl::Vector<Position> iteration is ~13% of all instructions. Inventory uses a persistent vector for O(1) clone, but a documented copy-on-write soundness bug forced self.positions = self.positions.iter().cloned().collect() on every reduce — an O(n) deep copy that discards the O(1)-clone benefit it was chosen for. That is invisible on simple, which never reduces a lot.

🤖 Generated with Claude Code

https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG

… ledger

Phase 0 of the performance work: make the measurement trustworthy before
optimizing against it.

The sole profiling workload contained no `{`, `^` or `#` anywhere. So it
never booked a lot, never matched a reduction, and never entered the three
whole-tree error passes in `parse_via_cst_inner` that those characters gate.
Every profile taken against it measured the cheapest path through the
parser.

That is not a small distortion. At an identical 2000 transactions:

    shape           instructions   vs simple
    simple           119,008,292      1.00x
    investment       278,162,145      2.34x
    tagged           185,439,627      1.56x
    multicurrency    174,720,996      1.47x

And the subsystem split does not merely shift, it INVERTS:

    subsystem      simple   investment   tagged   multicurrency
    parser          35.7%       15.1%     28.5%       35.0%
    core             7.9%       50.9%      3.6%        4.9%
    allocator       30.3%       21.7%     36.1%       33.3%
    rowan           22.9%       11.4%     31.0%       24.3%

Read `simple` alone and the conclusion is "make the parser faster". Read
`investment` and `rustledger-core` is half the program — the lot matching in
`Inventory`, which `simple` cannot reach at all. A plan built on the old
workload would have aimed at the wrong subsystem, which is the whole reason
this lands before any tuning.

The generator moves out of the workflow heredoc into
`scripts/gen-profile-workload.py`. A profile has to be reproducible locally,
and while it lived in the YAML the only way to see what was being measured
was to read the workflow — which is how it drifted this far unnoticed. The
cachegrind job now runs a matrix over all four shapes.

`scripts/check-profile-workloads.sh` asserts the two properties that make
these workloads worth anything, neither self-evident from the generator:
each shape LOADS CLEANLY (a workload with errors profiles the diagnostic
paths — a different program), and each shape still CONTAINS the feature it
exists for. `simple` is additionally asserted NOT to grow cost specs, tags or
links, since its job is to stay the cheap-path floor.

The guard is mutation-checked in both directions rather than assumed: a
generator that stops emitting `{...}` fails on the load check, and one that
drops `#tag` while still producing a valid ledger — the exact drift that
happened here — fails on the feature check with exit 1.
@robcohen
robcohen requested a review from a team as a code owner August 15, 2026 00:25
Copilot AI lite review requested due to automatic review settings August 15, 2026 00:25
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Adjusts the profiling infrastructure to measure multiple representative ledger “shapes” (instead of a single cheapest-path workload), so performance work targets the right subsystems in rustledger.

Changes:

  • Add a committed Python generator (scripts/gen-profile-workload.py) to produce deterministic profiling ledgers for multiple workload shapes.
  • Add a guard script (scripts/check-profile-workloads.sh) to ensure each shape both loads cleanly and still contains its intended feature.
  • Update the profiling GitHub Actions workflow to generate workloads via the script and to run cachegrind over a shape matrix.

Reviewed changes

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

File Description
scripts/gen-profile-workload.py New deterministic generator for multiple profiling workload shapes.
scripts/check-profile-workloads.sh New validation script to prevent workload drift (clean load + feature presence).
.github/workflows/profile.yml Switch workload generation to the committed generator; run cachegrind across a shape matrix and upload per-shape artifacts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/profile.yml Resolved
Comment thread .github/workflows/profile.yml Resolved
Comment thread scripts/gen-profile-workload.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 812
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Three Copilot findings on #2055, all valid, and one of them a breakage I
introduced.

The artifact rename to `cachegrind-instructions-${{ matrix.shape }}` was a
global replace, so it also hit the `trend` job's DOWNLOAD of that artifact —
a job with no matrix, where the context is unavailable. Trend would have
fetched nothing and the nightly data point would have silently stopped
being recorded.

`trend` now downloads `cachegrind-instructions-simple` explicitly. That
shape deliberately: the committed history on the `profiling` branch was
recorded from the old single workload, so tracking `simple` keeps the series
comparable. Per-shape trend points would need a schema change on that branch
and are left as a follow-up rather than smuggled in here.

The `profile` (heap + CPU) job had the same stray reference and is not a
matrix job either; it now names `simple` literally. The cachegrind job does
have the matrix, so its `|| 'simple'` fallback was never reachable and only
suggested otherwise — dropped.

Also replaces `commodities: list[str] = []` with an immutable `Sequence[str]
= ()` default. Not mutated today, but a mutable default is a footgun that
costs nothing to remove.

The workload guard still passes on all four shapes.
@robcohen
robcohen merged commit 8753e44 into main Aug 15, 2026
49 of 50 checks passed
@robcohen
robcohen deleted the perf/profile-workloads branch August 15, 2026 02:06
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