MTGBench improvement loop

Overview · Experiment index

Iteration 25: Consume owned mana-resolution values instead of cloning unchanged swaps

state rejected — failed gate ir4k
switch PHASE_MANA_INSTEAD_MOVE_LEGACY · branch loop/it25 · base 4ec0b9ef1 · candidate 363a1617d · took 1h 49m

Results

Verdict: TOO SMALL: only 0.08% fewer instructions, under the 0.3% floor. Cycles moved +3.93%, within this machine's noise (±6.4%): 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.08% instructions, same-arm spread 0.010%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.08%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,551,259,60721,549,017,5774,0005,387,5354,1783,248
optimized21,534,223,24221,533,259,5124,0005,383,4352,7312,686
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.93% — cycles-neutral (same-arm spread 6.36%)same within noise
IPC (instructions per cycle, higher is better)0.989 / 1.002same
backend stall / frontend stall (share of cycles)16.3% / 16.6%  ·  44.5% / 44.2%same
L1D / L2D refills per 1k instructions (cache misses)13.06 / 12.99  ·  11.31 / 11.30same
branch mispredicts per 1k instructions5.861 / 5.780same
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.10% fewer instructions, under the 0.3% floor. Cycles moved -0.44%, within this machine's noise (±4.4%): 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.10% 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.10%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,460,574,93677,454,671,87111,4186,783,81718,88812,934
optimized77,371,660,76077,383,632,10611,4186,776,81319,95512,223
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.44% — cycles-neutral (same-arm spread 4.44%)same within noise
IPC (instructions per cycle, higher is better)0.881 / 0.893same
backend stall / frontend stall (share of cycles)18.7% / 19.4%  ·  46.9% / 45.6%same
L1D / L2D refills per 1k instructions (cache misses)17.49 / 17.51  ·  13.84 / 13.77same
branch mispredicts per 1k instructions5.148 / 5.046same
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: 78 minreviewer: 0 mingate fmt: 0 mingate build: 16 mingate ir1k: 1 mingate ir4k: 3 min
planner 8mexecutor 78mreviewer 0mgate fmt 0mgate build 16mgate ir1k 1mgate ir4k 3m
executor: 12,716,384 in / 22,740 out tokensplanner: 2,695,203 in / 10,226 out tokensreviewer: 21,282 in / 616 out tokens

Mechanism. In mana_abilities.rs::apply_condition_instead_mana_swap, ordinary mana abilities return ability.clone() even though all three production callers already own the ResolvedAbility. Add a consuming helper that returns its input unchanged on those branches. Preserve the existing authoritative swap for a true ConditionInstead; on a false condition, move the else chain into the owned parent.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, measured auto-tap at 18.1% inclusive CPU. The newer docs/profiles/perf-20261002-1221/w0-owners-all.txt attributes 0.7% CPU to ResolvedAbility::clone and 0.4% to its destruction; clone shares reach 1.1% in window 2 and 1.4% in window 8. These are family bounds, not isolated measurements of this helper. Source inspection identifies an unconditional extra deep copy at each caller.

Counter and kill threshold. Existing profile rows: ResolvedAbility::clone and drop_in_place<ResolvedAbility>; xn5.67 auto_tap_mana_sources_inner. Expected instruction reduction: 0.4–0.9% per action at 4,000 actions, an unmeasured planning estimate. Copy savings may appear marginal in instructions despite a larger wall-clock effect.

Invariant. The returned resolved ability must match the old helper field-for-field, including source, controllers, chosen X, cost-paid snapshots, effect-shape fields and chain tails. Permanent differential regressions cover no subchain, an ordinary subchain, both ConditionInstead outcomes, and a true condition whose subeffect is not mana; production tests compare pools and complete ordered events.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 20s02,695,203 / 10,226
executorcodex / gpt-6-luna1h 18m012,716,384 / 22,740
reviewercodex / gpt-6.1-sol0m 30s021,282 / 616

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it25-build
ir1kpass0Ir -0.07% within +/-1%, same-arm spread 0.0274% | optimized 21,533,679,984 vs legacy 21,548,547,306 instructions; fingerprints match: True
ir4kFAIL0Ir -0.10% within +/-1%, same-arm spread 0.0155% | optimized 77,377,498,300 vs legacy 77,458,077,995 instructions; fingerprints match: True

Write-up: 2026-10-02 - Loop iteration 25: Consume owned mana-resolution values instead of cloning unchanged swaps (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_MANA_INSTEAD_MOVE_LEGACY, mechanism class copy. Mechanism: In mana_abilities.rs::apply_condition_instead_mana_swap, ordinary mana abilities return ability.clone() even though all three production callers already own the ResolvedAbility. Add a consuming helper that returns its input unchanged on those branches. Preserve the existing authoritative swap for a true ConditionInstead; on a false condition, move the else chain into the owned parent. Invariant: The returned resolved ability must match the old helper field-for-field, including source, controllers, chosen X, cost-paid snapshots, effect-shape fields and chain tails. Permanent differential regressions cover no subchain, an ordinary subchain, both ConditionInstead outcomes, and a true condition whose subeffect is not mana; production tests compare pools and complete ordered events.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.07% within +/-1%, same-arm spread 0.0274%
ir4kNOIr -0.10% within +/-1%, same-arm spread 0.0155%

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