MTGBench improvement loop

Overview · Experiment index

Iteration 34: Filter state-trigger definitions before cloning

state confirm-pending — gate ir4k: marginal instruction reduction (copy); the workstation wall-clock decides
switch PHASE_STATE_TRIGGER_PREFILTER_LEGACY · branch loop/it34 · base 4ec0b9ef1 · candidate cb88817bd · took 2h 16m

Results

Verdict: TOO SMALL: only 0.23% fewer instructions, under the 0.3% floor. Cycles moved +2.47%, within this machine's noise (±6.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: 1,000 actions (screen) — -0.23% instructions, same-arm spread 0.017%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.23%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,098,844,07522,100,865,9074,0005,524,9642,4422,311
optimized22,047,544,99522,051,245,4334,0005,512,3492,5152,419
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.47% — cycles-neutral (same-arm spread 6.15%)same within noise
IPC (instructions per cycle, higher is better)0.991 / 1.004same
backend stall / frontend stall (share of cycles)16.6% / 17.8%  ·  43.8% / 42.2%less waiting
L1D / L2D refills per 1k instructions (cache misses)12.67 / 12.71  ·  11.02 / 11.09same
branch mispredicts per 1k instructions5.793 / 5.797same
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: MARGINAL: 0.89% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -0.64%, 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: 4,000 actions (verdict) — -0.89% instructions, same-arm spread 0.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.89%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,059,165,45481,055,310,93911,4187,099,07518,20811,954
optimized80,333,203,52180,333,174,12111,4187,035,66220,24512,638
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.64% — cycles-neutral (same-arm spread 5.29%)same within noise
IPC (instructions per cycle, higher is better)0.914 / 0.904same
backend stall / frontend stall (share of cycles)20.8% / 19.9%  ·  42.9% / 44.5%same
L1D / L2D refills per 1k instructions (cache misses)16.64 / 16.76  ·  13.46 / 13.44same
branch mispredicts per 1k instructions5.196 / 4.964same
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/it34-parity-20261003-113504-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: 56 minreviewer: 0 mingate fmt: 0 mingate build: 19 mingate ir1k: 1 mingate ir4k: 3 mingate check: 13 mingate focused: 26 mingate parity: 5 min
planner 9mexecutor 56mreviewer 0mgate fmt 0mgate build 19mgate ir1k 1mgate ir4k 3mgate check 13mgate focused 26mgate parity 5m
executor: 23,233,544 in / 30,608 out tokensplanner: 2,758,210 in / 9,715 out tokensreviewer: 20,528 in / 680 out tokens

Mechanism. In game/triggers.rs:10897, check_state_triggers clones every active trigger into a Vec, then discards definitions whose mode is not StateCondition. Apply that mode filter before cloning, retaining the existing condition evaluation and pending-trigger construction.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, references bench/reports/uprof-xn565-20260923-owners-all.txt: check_state_triggers owns 0.8% of process CPU. owners-alloc.txt attributes 0.2% directly to its allocations. These overlap; clone descendants may have other owners. The ordinary-trigger fraction is unmeasured, and the profile predates subsequent loop changes.

Counter and kill threshold. Existing xn5.67 check_state_triggers owner rows: 0.8% CPU, including 0.2% allocator ownership. Expected instruction reduction: 0.3–0.8% per action at 4,000 actions, an unmeasured forecast likely to enter the marginal band. Instruction counts can under-report clone and allocation savings.

Invariant. Only StateCondition definitions reach the existing evaluation body. Preserve functioning-ability gates, definition order, source snapshots, already-on-stack suppression and APNAP placement. A permanent explicit-arm regression must compare serialized state and stack for mixed ordinary/state definitions, true and false conditions, phased-out sources and an already-stacked state trigger.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol9m 6s02,758,210 / 9,715
executorcodex / gpt-6-luna56m 30s023,233,544 / 30,608
reviewercodex / gpt-6.1-sol0m 43s020,528 / 680

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it34-build
ir1kpass0Ir -0.24% within +/-1%, same-arm spread 0.0269% | optimized 22,048,033,525 vs legacy 22,100,923,816 instructions; fingerprints match: True
ir4kFAIL0Ir -0.90% within +/-1%, same-arm spread 0.0128% | optimized 80,332,143,590 vs legacy 81,060,066,376 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 it34-parity

Write-up: 2026-10-03 - Loop iteration 34: Filter state-trigger definitions before cloning (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_STATE_TRIGGER_PREFILTER_LEGACY, mechanism class copy. Mechanism: In game/triggers.rs:10897, check_state_triggers clones every active trigger into a Vec, then discards definitions whose mode is not StateCondition. Apply that mode filter before cloning, retaining the existing condition evaluation and pending-trigger construction. Invariant: Only StateCondition definitions reach the existing evaluation body. Preserve functioning-ability gates, definition order, source snapshots, already-on-stack suppression and APNAP placement. A permanent explicit-arm regression must compare serialized state and stack for mixed ordinary/state definitions, true and false conditions, phased-out sources and an already-stacked state trigger.

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.0269%
ir4kmarginal: workstation checkIr -0.90% within +/-1%, same-arm spread 0.0128%
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:14 · read-only · refreshes every 30 s