MTGBench improvement loop

Overview · Experiment index

Iteration 15: Skip empty replacement sources before iterator setup

state retained — instruction-count retained; awaiting workstation wall-clock confirmation
switch PHASE_REPLACEMENT_EMPTY_SOURCE_LEGACY · branch loop/it15 · base 4ec0b9ef1 · candidate 91fa27e15 · took 1h 14m

Results

Verdict: MARGINAL: 0.92% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -2.00%, within this machine's noise (±5.3%): 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.92% instructions, same-arm spread 0.026%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.92%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy20,817,710,04820,812,215,0824,0005,203,7412,8892,767
optimized20,623,178,00020,625,801,9304,0005,156,1222,4672,487
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-2.00% — cycles-neutral (same-arm spread 5.33%)same within noise
IPC (instructions per cycle, higher is better)0.983 / 0.987same
backend stall / frontend stall (share of cycles)19.6% / 20.2%  ·  42.4% / 41.7%same
L1D / L2D refills per 1k instructions (cache misses)13.34 / 13.43  ·  11.71 / 11.75same
branch mispredicts per 1k instructions6.056 / 5.875same
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.02% fewer instructions, above the 1% bar. Cycles moved -1.29%, 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: 4,000 actions (verdict) — -1.02% instructions, same-arm spread 0.037%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.02%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,881,172,44677,865,921,35011,4186,820,24420,58912,945
optimized77,067,439,12177,095,610,58711,4186,750,87817,71311,651
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.29% — cycles-neutral (same-arm spread 2.50%)same within noise
IPC (instructions per cycle, higher is better)0.896 / 0.894same
backend stall / frontend stall (share of cycles)23.5% / 23.4%  ·  41.1% / 41.3%same
L1D / L2D refills per 1k instructions (cache misses)17.30 / 17.39  ·  13.94 / 13.97same
branch mispredicts per 1k instructions5.251 / 5.219same
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/it15-parity-20261001-214200-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: 7 minexecutor: 22 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 mingate check: 6 mingate focused: 16 mingate parity: 4 min
planner 7mexecutor 22mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3mgate check 6mgate focused 16mgate parity 4m
executor: 6,771,812 in / 16,628 out tokensplanner: 1,900,375 in / 9,512 out tokensreviewer: 20,745 in / 555 out tokens

Mechanism. In functioning_abilities.rs:520, active_replacements evaluates object_functions and constructs the inner enumerate/filter/map chain for every stored object, including objects with no replacement definitions. Screen empty definition lists before that setup; retain the existing functioning gate and definition enumeration for surviving sources.

Evidence. xn5.69, docs/stage0-decision-memo.md:5379, measures active scan/staging at 322.749/309.324 ms against 8,561/7,659 ms contract+apply: 3.77%/4.04%. Raw bundles: bench/reports/xn569-counter-s91-20260924-131701-* and xn569-counter-s42-20260924-132036-*. This targets scanning, unlike the rejected bucket representation change. The timer bounds the family; the empty-source fraction is unmeasured, and HAMT traversal remains.

Counter and kill threshold. Existing replacement_index_active_scan_ns bounds the affected family. Expected instruction reduction: 0.4–1.0% per action at 4,000 actions, an unmeasured planning estimate. Compiler elimination of existing empty-iterator work could push it below 0.3%.

Invariant. Preserve the ordered sequence of (definition index, source, definition), hence replacement ordinals and candidate ordering. Empty sources contribute no entries today. Preserve every zone and functioning check; leave floating replacements, liminal entries, index lifetime and replacement appliers untouched. Add a permanent differential regression covering empty sources interspersed with functioning, phased-out and command-zone sources, plus fork-local definition insertion/removal.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol7m 43s01,900,375 / 9,512
executorcodex / gpt-6-luna22m 14s06,771,812 / 16,628
reviewercodex / gpt-6.1-sol0m 26s020,745 / 555

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it15-build
ir1kpass0Ir -0.91% within +/-1%, same-arm spread 0.0264% | optimized 20,625,844,906 vs legacy 20,815,400,310 instructions; fingerprints match: True
ir4kpass0Ir -1.02% (threshold -1%), same-arm spread 0.0365% | optimized 77,078,617,470 vs legacy 77,876,448,456 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 it15-parity

Write-up: 2026-10-01 - Loop iteration 15: Skip empty replacement sources before iterator setup (retained)

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

Automated loop result on homelab (aarch64). Switch PHASE_REPLACEMENT_EMPTY_SOURCE_LEGACY, mechanism class compute. Mechanism: In functioning_abilities.rs:520, active_replacements evaluates object_functions and constructs the inner enumerate/filter/map chain for every stored object, including objects with no replacement definitions. Screen empty definition lists before that setup; retain the existing functioning gate and definition enumeration for surviving sources. Invariant: Preserve the ordered sequence of (definition index, source, definition), hence replacement ordinals and candidate ordering. Empty sources contribute no entries today. Preserve every zone and functioning check; leave floating replacements, liminal entries, index lifetime and replacement appliers untouched. Add a permanent differential regression covering empty sources interspersed with functioning, phased-out and command-zone sources, plus fork-local definition insertion/removal.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.91% within +/-1%, same-arm spread 0.0264%
ir4kyesIr -1.02% (threshold -1%), same-arm spread 0.0365%
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:17 · read-only · refreshes every 30 s