MTGBench improvement loop

Overview · Experiment index

Iteration 27: Share live mana definitions during synchronous activation

state rejected — failed gate ir4k
switch PHASE_MANA_DEFINITION_VIEW_LEGACY · branch loop/it27 · base 4ec0b9ef1 · candidate 36b2f3f33 · took 1h 47m

Results

Verdict: TOO SMALL: only 0.12% fewer instructions, under the 0.3% floor. Cycles moved +0.99%, within this machine's noise (±5.6%): 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.12% instructions, same-arm spread 0.009%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.12%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,100,040,95922,099,342,4454,0005,524,9232,6952,473
optimized22,074,485,45822,072,580,0584,0005,518,3833,0712,983
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+0.99% — cycles-neutral (same-arm spread 5.58%)same within noise
IPC (instructions per cycle, higher is better)1.015 / 1.031same
backend stall / frontend stall (share of cycles)19.3% / 20.5%  ·  42.1% / 40.1%less waiting
L1D / L2D refills per 1k instructions (cache misses)12.62 / 12.69  ·  11.29 / 11.11same
branch mispredicts per 1k instructions5.623 / 5.660same
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.17% fewer instructions, under the 0.3% floor. Cycles moved +0.52%, within this machine's noise (±3.2%): 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.17% instructions, same-arm spread 0.028%, 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.17%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,044,317,82681,066,912,17611,4187,098,93319,96713,706
optimized80,919,927,84680,923,137,23411,4187,087,19018,45012,273
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+0.52% — cycles-neutral (same-arm spread 3.18%)same within noise
IPC (instructions per cycle, higher is better)0.914 / 0.915same
backend stall / frontend stall (share of cycles)25.3% / 25.6%  ·  39.1% / 38.8%same
L1D / L2D refills per 1k instructions (cache misses)16.75 / 16.75  ·  13.45 / 13.57same
branch mispredicts per 1k instructions5.247 / 5.259same
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: 8 minexecutor: 75 minreviewer: 0 mingate fmt: 0 mingate build: 17 mingate ir1k: 1 mingate ir4k: 3 min
planner 8mexecutor 75mreviewer 0mgate fmt 0mgate build 17mgate ir1k 1mgate ir4k 3m
executor: 50,143,199 in / 44,232 out tokensplanner: 3,131,244 in / 10,389 out tokensreviewer: 20,935 in / 837 out tokens

Mechanism. At game/mana_abilities.rs:2281, mana_ability_definition deep-clones an AbilityDefinition on every lookup. Return a private definition holder backed by the source's existing Arc<Vec<AbilityDefinition>> and the selected index. Its owned variant preserves the current deep-clone path. Use the holder at the four existing callers without changing when definitions are selected.

Evidence. docs/profiles/perf-20261002-1221/summary.md measures AbilityDefinition::clone at 1.0–1.4% CPU across five windows, 1.3% in window 0; destruction owns another 0.5% across windows. These are family ceilings, not measurements of this lookup alone. The matching source inspection identifies repeated whole-definition copies. Memo xn5.67 at L4904 additionally bounds the enclosing mana-cost continuation family at 16.7% inclusive CPU; that overlapping share is not additional credit.

Counter and kill threshold. Existing October 2 AbilityDefinition::clone and drop_in_place<AbilityDefinition> profile rows. Expected reduction: 0.4–0.9% instructions per action at 4,000 actions, an unmeasured hypothesis likely to be marginal. The lookup's exclusive fraction is unknown, and instruction counts can under-report copy savings.

Invariant. Preserve live-definition precedence over ability_snapshot, lookup timing, ability indices, errors, payment order and all fingerprints. Holding the abilities Arc preserves the selected definition across subsequent source mutation just as the old owned clone did. Each later stage must perform its original fresh lookup. Permanently compare both arms for live/snapshot disagreement, missing sources, same-revision ability replacement, source sacrifice, suspended payment and fork isolation.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 59s03,131,244 / 10,389
executorcodex / gpt-6-luna1h 15m050,143,199 / 44,232
reviewercodex / gpt-6.1-sol0m 36s020,935 / 837

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it27-build
ir1kpass0Ir -0.13% within +/-1%, same-arm spread 0.0160% | optimized 22,072,675,232 vs legacy 22,100,495,811 instructions; fingerprints match: True
ir4kFAIL0Ir -0.16% within +/-1%, same-arm spread 0.0279% | optimized 80,926,514,016 vs legacy 81,057,683,743 instructions; fingerprints match: True

Write-up: 2026-10-02 - Loop iteration 27: Share live mana definitions during synchronous activation (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_MANA_DEFINITION_VIEW_LEGACY, mechanism class copy. Mechanism: At game/mana_abilities.rs:2281, mana_ability_definition deep-clones an AbilityDefinition on every lookup. Return a private definition holder backed by the source's existing Arc<Vec<AbilityDefinition>> and the selected index. Its owned variant preserves the current deep-clone path. Use the holder at the four existing callers without changing when definitions are selected. Invariant: Preserve live-definition precedence over ability_snapshot, lookup timing, ability indices, errors, payment order and all fingerprints. Holding the abilities Arc preserves the selected definition across subsequent source mutation just as the old owned clone did. Each later stage must perform its original fresh lookup. Permanently compare both arms for live/snapshot disagreement, missing sources, same-revision ability replacement, source sacrifice, suspended payment and fork isolation.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.13% within +/-1%, same-arm spread 0.0160%
ir4kNOIr -0.16% within +/-1%, same-arm spread 0.0279%

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:16 · read-only · refreshes every 30 s