Repository navigation
perf(profile): profile four workload shapes, not one unrepresentative ledger - #2055
Merged
Merged
Conversation
… 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
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.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
enabled auto-merge (squash)
August 15, 2026 00:37
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inparse_via_cst_innerthat those characters gate.At an identical 2000 transactions:
simpleThe subsystem split doesn't shift — it inverts
Read
simplealone and the conclusion is "make the parser faster." Readinvestmentandrustledger-coreis half the program — the lot matching inInventory, whichsimplecannot 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:simpleis 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#tagwhile 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.Inventoryuses a persistent vector for O(1) clone, but a documented copy-on-write soundness bug forcedself.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 onsimple, which never reduces a lot.🤖 Generated with Claude Code
https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG