MTGBench improvement loop

Overview · Experiment index

Iteration 24: Filter scoped mana-concession statics before evaluating conditions

state retained — instruction-count retained; awaiting workstation wall-clock confirmation
switch PHASE_MANA_CONCESSION_CONDITION_PREFILTER_LEGACY · branch loop/it24 · base 4ec0b9ef1 · candidate 5d6b7ff6f · took 4h 53m

Results

Verdict: TOO SMALL: only 0.24% fewer instructions, under the 0.3% floor. Cycles moved -0.61%, within this machine's noise (±4.6%): the time effect is too small to see here; only the PC wall-clock can say. Watch: branch mispredicts +7% per instruction, so part of the saving may be paid back as slower memory or branching. The final word is always the PC wall-clock.
Gate: 1,000 actions (screen) — -0.24% instructions, same-arm spread 0.012%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.24%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,088,057,69622,086,481,9044,0005,521,8172,6642,489
optimized22,036,572,70122,033,882,1484,0005,508,8072,7122,644
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.61% — cycles-neutral (same-arm spread 4.58%)same within noise
IPC (instructions per cycle, higher is better)1.021 / 1.025same
backend stall / frontend stall (share of cycles)18.8% / 17.9%  ·  41.8% / 42.7%same
L1D / L2D refills per 1k instructions (cache misses)12.72 / 12.65  ·  10.86 / 11.10same
branch mispredicts per 1k instructions6.040 / 5.658more
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.57% fewer instructions, above the 1% bar. Cycles moved +1.38%, within this machine's noise (±2.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: 4,000 actions (verdict) — -1.57% instructions, same-arm spread 0.042%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.57%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy80,975,733,69881,009,396,91211,4187,093,41118,93312,407
optimized79,723,483,07379,716,587,80111,4186,981,96120,26512,869
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.38% — cycles-neutral (same-arm spread 2.78%)same within noise
IPC (instructions per cycle, higher is better)0.906 / 0.935same
backend stall / frontend stall (share of cycles)20.6% / 23.1%  ·  44.1% / 40.3%less waiting
L1D / L2D refills per 1k instructions (cache misses)16.87 / 16.74  ·  13.47 / 13.32same
branch mispredicts per 1k instructions5.105 / 4.979same
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/it24-parity-20261002-145720-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: 9 minexecutor: 93 minreviewer: 0 mingate fmt: 0 mingate build: 16 mingate ir1k: 1 mingate ir4k: 3 mingate check: 22 mingate focused: 49 mingate parity: 5 minnot attributed: 90 min
planner 9mexecutor 93mreviewer 0mgate fmt 0mgate build 16mgate ir1k 1mgate ir4k 3mgate check 22mgate focused 49mgate parity 5mnot attributed 90m
executor: 13,221,264 in / 23,166 out tokensplanner: 3,249,781 in / 10,621 out tokensreviewer: 24,030 in / 627 out tokens

Mechanism. In static_abilities.rs:1070 and :1108, replace game_active_statics iteration with game_functioning_statics, select the relevant SpendManaAsAnyColor shape, then evaluate its condition through the existing layers authority. This avoids evaluating unrelated static conditions on every scoped mana-payment query.

Evidence. xn5.67, docs/stage0-decision-memo.md:4904, identifies allocator costs inside static_abilities::player_can_spend_as_any_color_for_activation_source. bench/reports/uprof-xn565-20260923-owners-alloc.txt attributes 0.4% of process CPU directly to this caller. That bounds an allocation component; the complete query and removable condition-evaluation share were not measured separately.

Counter and kill threshold. Existing xn5.67 allocator-owner row: player_can_spend_as_any_color_for_activation_source, 0.4% process CPU. Expected reduction: 0.4–0.9% instructions per action at 4,000 actions, an unmeasured planning estimate.

Invariant. Both scoped queries must return identical booleans. For SpendManaAsAnyColor definitions, game_functioning_statics preserves the same source, phasing and zone gates; evaluate the condition with exactly the controller/source arguments used by active_static_definitions. Preserve the unfiltered base query and scope distinctions. Add a permanent differential regression covering irrelevant conditional statics, true/false matching conditions, phased sources, command-zone opt-in, and spell-only versus activation-only concessions.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol9m 40s03,249,781 / 10,621
executorcodex / gpt-6-luna1h 33m013,221,264 / 23,166
reviewercodex / gpt-6.1-sol0m 34s024,030 / 627

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it24-build
ir1kpass0Ir -0.24% within +/-1%, same-arm spread 0.0122% | optimized 22,034,907,512 vs legacy 22,087,716,602 instructions; fingerprints match: True
ir4kpass0Ir -1.56% (threshold -1%), same-arm spread 0.0416% | optimized 79,725,361,940 vs legacy 80,990,658,011 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 it24-parity

Write-up: 2026-10-02 - Loop iteration 24: Filter scoped mana-concession statics before evaluating conditions (retained)

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

Automated loop result on homelab (aarch64). Switch PHASE_MANA_CONCESSION_CONDITION_PREFILTER_LEGACY, mechanism class compute. Mechanism: In static_abilities.rs:1070 and :1108, replace game_active_statics iteration with game_functioning_statics, select the relevant SpendManaAsAnyColor shape, then evaluate its condition through the existing layers authority. This avoids evaluating unrelated static conditions on every scoped mana-payment query. Invariant: Both scoped queries must return identical booleans. For SpendManaAsAnyColor definitions, game_functioning_statics preserves the same source, phasing and zone gates; evaluate the condition with exactly the controller/source arguments used by active_static_definitions. Preserve the unfiltered base query and scope distinctions. Add a permanent differential regression covering irrelevant conditional statics, true/false matching conditions, phased sources, command-zone opt-in, and spell-only versus activation-only concessions.

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