MTGBench improvement loop

Overview · Experiment index

Iteration 41: Avoid constructing discarded mana-production receipts

state rejected — failed gate ir4k
switch PHASE_MANA_PRODUCTION_RECEIPT_LEGACY · branch loop/it41 · base 4ec0b9ef1 · candidate 78037158e · took 51m 2s

Results

Verdict: TOO SMALL: only 0.01% fewer instructions, under the 0.3% floor. Cycles moved +4.76%, within this machine's noise (±12.8%): the time effect is too small to see here; only the PC wall-clock can say. Cache misses and branch mispredicts per instruction are about unchanged, so no hidden cost shows up. The final word is always the PC wall-clock.
Gate: 1,000 actions (screen) — -0.01% instructions, same-arm spread 0.030%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.01%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,747,458,12321,740,922,7304,0005,436,0482,4012,282
optimized21,742,458,27321,741,849,8844,0005,435,5392,7032,627
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.
Hardware counters (optimized / legacy)ValueReading
cycles, minimum of the repeats+4.76% — cycles-neutral (same-arm spread 12.80%)same within noise
IPC (instructions per cycle, higher is better)0.966 / 0.985same
backend stall / frontend stall (share of cycles)18.0% / 21.0%  ·  44.8% / 40.9%less waiting
L1D / L2D refills per 1k instructions (cache misses)12.86 / 12.89  ·  11.21 / 11.41same
branch mispredicts per 1k instructions5.676 / 5.793same
Green = better, red = worse, grey = about the same (5% band). Cycles are the closest thing to time that the shared VM does not distort. Fewer instructions with more cycles means the saving does not show up as time; such a candidate goes to the workstation wall-clock instead of being retained.
Verdict: TOO SMALL: only 0.00% fewer instructions, under the 0.3% floor. Cycles moved +3.79%, within this machine's noise (±1.9%): the time effect is too small to see here; only the PC wall-clock can say. Cache misses and branch mispredicts per instruction are about unchanged, so no hidden cost shows up. The final word is always the PC wall-clock.
Gate: 4,000 actions (verdict) — -0.00% instructions, same-arm spread 0.015%, equal work: yes, fingerprints match: yes
Gate FAILED: the harness refused this A/B (exit 0); see the write-up below. These counts are not a valid measurement.
-1% retain-0.3% kill0-0.00%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,046,477,25178,046,080,26011,4186,835,37218,29112,148
optimized78,050,410,94978,038,558,87011,4186,835,21521,08513,066
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.
Hardware counters (optimized / legacy)ValueReading
cycles, minimum of the repeats+3.79% — cycles-neutral (same-arm spread 1.91%)same within noise
IPC (instructions per cycle, higher is better)0.859 / 0.892same
backend stall / frontend stall (share of cycles)18.1% / 27.3%  ·  49.3% / 37.9%less waiting
L1D / L2D refills per 1k instructions (cache misses)17.33 / 17.39  ·  13.71 / 13.69same
branch mispredicts per 1k instructions4.973 / 4.997same
Green = better, red = worse, grey = about the same (5% band). Cycles are the closest thing to time that the shared VM does not distort. Fewer instructions with more cycles means the saving does not show up as time; such a candidate goes to the workstation wall-clock instead of being retained.

Where the time went

planner: 10 minexecutor: 23 minreviewer: 0 mingate fmt: 0 mingate build: 10 mingate ir1k: 1 mingate ir4k: 3 min
planner 10mexecutor 23mreviewer 0mgate fmt 0mgate build 10mgate ir1k 1mgate ir4k 3m
executor: 4,898,542 in / 13,374 out tokensplanner: 5,057,283 in / 13,384 out tokensreviewer: 21,783 in / 889 out tokens

Mechanism. mana_abilities.rs::produce_mana_from_ability ignores the Vec<ManaUnit> returned by mana_payment.rs::produce_mana_with_attributes_from_source_quality. Nevertheless, production allocates that vector, and GameState::add_mana_to_pool clones each unit into its journal command while retaining the original for the return value. Add an internal production path that deposits and journals mana without retaining a receipt. Keep replacement processing, pool insertion and event emission shared with the existing implementation.

Evidence. docs/profiles/uprof-20261002-1125/summary.md attributes 0.7–1.6% directly owned CPU to produce_mana_with_attributes_from_source_quality across five windows, including 1.5% in window 0. Its w0-owners-alloc.txt attributes 0.5% allocation/copy CPU one caller level above that function. These are enclosing bounds, not isolated receipt costs. The older xn5.67 memo section at docs/stage0-decision-memo.md:4904 independently identifies this production path. The captures predate subsequent loop changes.

Counter and kill threshold. Existing workstation profile rows: produce_mana_with_attributes_from_source_quality, 1.5% owned CPU in window 0; allocation/copy attribution one level above it, 0.5%. Expected instruction reduction: 0.3–0.7% per action at 4,000 actions, an unmeasured estimate likely to enter the marginal band. Allocation savings may exceed their instruction-count effect.

Invariant. Preserve pooled units, pip allocation, producer identities, journal commands, emitted event order, layer dirtiness and replacement outcomes exactly. Preserve the existing pip-counter advance even for an unknown recipient. Public receipt-returning APIs keep their current behavior. Permanent differential tests compare complete resulting states and events for ordinary, restricted, snow, multiplied, prevented and unknown-recipient production, including fork isolation.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol10m 46s05,057,283 / 13,384
executorcodex / gpt-6-luna23m 8s04,898,542 / 13,374
reviewercodex / gpt-6.1-sol0m 40s021,783 / 889

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it41-build
ir1kpass0Ir -0.02% within +/-1%, same-arm spread 0.0321% | optimized 21,742,126,677 vs legacy 21,745,430,161 instructions; fingerprints match: True
ir4kFAIL0Ir -0.01% within +/-1%, same-arm spread 0.0454% | optimized 78,034,655,625 vs legacy 78,044,303,452 instructions; fingerprints match: True

Write-up: 2026-10-03 - Loop iteration 41: Avoid constructing discarded mana-production receipts (rejected)

Status: rejected (loop, instruction-count gate; wall-clock not yet confirmed)

Automated loop result on homelab (aarch64). Switch PHASE_MANA_PRODUCTION_RECEIPT_LEGACY, mechanism class allocation. Mechanism: mana_abilities.rs::produce_mana_from_ability ignores the Vec<ManaUnit> returned by mana_payment.rs::produce_mana_with_attributes_from_source_quality. Nevertheless, production allocates that vector, and GameState::add_mana_to_pool clones each unit into its journal command while retaining the original for the return value. Add an internal production path that deposits and journals mana without retaining a receipt. Keep replacement processing, pool insertion and event emission shared with the existing implementation. Invariant: Preserve pooled units, pip allocation, producer identities, journal commands, emitted event order, layer dirtiness and replacement outcomes exactly. Preserve the existing pip-counter advance even for an unknown recipient. Public receipt-returning APIs keep their current behavior. Permanent differential tests compare complete resulting states and events for ordinary, restricted, snow, multiplied, prevented and unknown-recipient production, including fork isolation.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.02% within +/-1%, same-arm spread 0.0321%
ir4kNOIr -0.01% within +/-1%, same-arm spread 0.0454%

Wall-clock confirmation on the workstation is required before this counts as a speedup; instruction count is a screen, not a time prediction.

generated 2026-11-28 18:17:10 · read-only · refreshes every 30 s