MTGBench improvement loop

Overview · Experiment index

Iteration 19: Remove boxed allocation from functioning-static iteration

state retained — instruction-count retained; awaiting workstation wall-clock confirmation
switch PHASE_STATIC_ITERATOR_BOX_LEGACY · branch loop/it19 · base 4ec0b9ef1 · candidate 1b94e59da · took 2h 3m

Results

Verdict: MARGINAL: 0.83% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -0.50%, within this machine's noise (±2.5%): 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.83% instructions, same-arm spread 0.015%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.83%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy20,740,315,24120,742,934,4564,0005,185,4062,5952,408
optimized20,568,084,26420,571,162,6374,0005,142,4062,6462,579
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.50% — cycles-neutral (same-arm spread 2.53%)same within noise
IPC (instructions per cycle, higher is better)0.991 / 1.006same
backend stall / frontend stall (share of cycles)21.7% / 22.5%  ·  39.8% / 38.5%same
L1D / L2D refills per 1k instructions (cache misses)13.57 / 13.46  ·  11.74 / 11.60same
branch mispredicts per 1k instructions6.035 / 5.960same
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: GOOD: 1.58% fewer instructions, above the 1% bar. Cycles moved -1.03%, within this machine's noise (±2.1%): 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) — -1.58% instructions, same-arm spread 0.003%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.58%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,615,786,70677,614,520,16211,4186,797,61418,70711,762
optimized76,388,888,86576,391,188,54111,4186,690,31719,83512,708
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-1.03% — cycles-neutral (same-arm spread 2.06%)same within noise
IPC (instructions per cycle, higher is better)0.896 / 0.897same
backend stall / frontend stall (share of cycles)26.4% / 22.9%  ·  37.9% / 41.8%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.49 / 17.33  ·  14.01 / 13.86same
branch mispredicts per 1k instructions5.564 / 5.355same
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.
Gate: parity (7 seeds, decks rotate per seed)
coverage: 253 distinct cards cast, 35 action kinds, 41 decision kinds, 59 event kinds, max battlefield 35, max stack 5
coverage: 143 of 257 engine counters were nonzero somewhere (unioned over 7 seeds; decks rotate per seed)
parity: 1 matched, 6 matched with an engine rejection in both arms, 0 diverged, 0 arm failures; summary /data/mtgbench/edh-play/bench/reports/it19-parity-20261002-041802-parity.json
9 games ended early on an engine rejection (counted over both arms). A rejection that happens identically in both arms is a match, but those games never reach their late game, so late-game behaviour of those decks is not exercised.

Where the time went

planner: 10 minexecutor: 39 minreviewer: 0 mingate fmt: 0 mingate build: 12 mingate ir1k: 1 mingate ir4k: 3 mingate check: 18 mingate focused: 32 mingate parity: 5 min
planner 10mexecutor 39mreviewer 0mgate fmt 0mgate build 12mgate ir1k 1mgate ir4k 3mgate check 18mgate focused 32mgate parity 5m
executor: 4,489,432 in / 14,688 out tokensplanner: 4,781,556 in / 11,233 out tokensreviewer: 21,467 in / 721 out tokens

Mechanism. At functioning_abilities.rs:248–281, active_static_definitions allocates a Box<dyn Iterator> for each ordinary object visit. Return a concrete iterator that walks the borrowed definition slice with the identical functioning predicate. Carry the original boxed iterator as the legacy variant of the same iterator wrapper.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, identifies allocation traffic as a remaining cost. Its linked uprof-xn565-20260923-owners-all.txt attributes 1.6% of process CPU to spell_objects_available_to_cast; owners-alloc.txt attributes 0.9% specifically to its allocation/copy family. That function reaches active_static_definitions through graveyard and library permission scans. These are enclosing bounds; the Box allocation itself has no exclusive timer. The profile predates subsequent loop changes.

Counter and kill threshold. Existing xn5.67 owner rows: spell_objects_available_to_cast 1.6% CPU, including 0.9% allocation/copy ownership. Expected instruction reduction: 0.4–0.9% per action, a hypothesis likely to enter the marginal band because instructions under-report allocator savings. Apply the loop's existing 1,000/4,000-action gates.

Invariant. Both iterator variants yield the same ordered definition references and evaluate the same conditions in the same order. Preserve phasing, CDA zone admission, command-zone opt-ins, Room door gates and self-referential stack prohibitions. Add a permanent differential regression comparing full iteration and short-circuit find/any results across these cases, including empty collections and same-revision definition mutation.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol10m 26s04,781,556 / 11,233
executorcodex / gpt-6-luna39m 3s04,489,432 / 14,688
reviewercodex / gpt-6.1-sol0m 36s021,467 / 721

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it19-build
ir1kpass0Ir -0.83% within +/-1%, same-arm spread 0.0150% | optimized 20,569,797,130 vs legacy 20,741,141,255 instructions; fingerprints match: True
ir4kpass0Ir -1.57% (threshold -1%), same-arm spread 0.0122% | optimized 76,391,778,710 vs legacy 77,612,212,970 instructions; fingerprints match: True
checkpass0
focusedpass0
paritypass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode parity -Seeds 1,2,3,5,7,11,13 -Actions 1000 -CargoProfile bench-fast-inc -Label it19-parity

Write-up: 2026-10-02 - Loop iteration 19: Remove boxed allocation from functioning-static iteration (retained)

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

Automated loop result on homelab (aarch64). Switch PHASE_STATIC_ITERATOR_BOX_LEGACY, mechanism class allocation. Mechanism: At functioning_abilities.rs:248–281, active_static_definitions allocates a Box<dyn Iterator> for each ordinary object visit. Return a concrete iterator that walks the borrowed definition slice with the identical functioning predicate. Carry the original boxed iterator as the legacy variant of the same iterator wrapper. Invariant: Both iterator variants yield the same ordered definition references and evaluate the same conditions in the same order. Preserve phasing, CDA zone admission, command-zone opt-ins, Room door gates and self-referential stack prohibitions. Add a permanent differential regression comparing full iteration and short-circuit find/any results across these cases, including empty collections and same-revision definition mutation.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.83% within +/-1%, same-arm spread 0.0150%
ir4kyesIr -1.57% (threshold -1%), same-arm spread 0.0122%
checkyes
focusedyes
parityyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode parity -Seeds 1,2,3,5,7,11,1

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