MTGBench improvement loop

Overview · Experiment index

Iteration 30: Avoid unchanged casting-permission expiry writes

state retained — instruction-count retained; awaiting workstation wall-clock confirmation
switch PHASE_PERMISSION_EXPIRY_WRITES_LEGACY · branch loop/it30 · base 4ec0b9ef1 · candidate 0886252ed · took 1h 37m

Results

Verdict: GOOD: 2.96% fewer instructions, above the 1% bar. Cycles moved -8.06%, within this machine's noise (±5.9%): 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) — -2.96% instructions, same-arm spread 0.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-2.96%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy20,978,013,29020,978,973,4074,0005,244,6233,4553,283
optimized20,356,549,03220,356,821,8354,0005,089,1712,5002,167
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-8.06% — cycles-neutral (same-arm spread 5.90%)same within noise
IPC (instructions per cycle, higher is better)0.982 / 0.953same
backend stall / frontend stall (share of cycles)16.8% / 17.2%  ·  45.2% / 45.9%same
L1D / L2D refills per 1k instructions (cache misses)13.09 / 13.38  ·  11.45 / 11.62same
branch mispredicts per 1k instructions6.131 / 5.919same
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.98% fewer instructions, above the 1% bar. Cycles agree (-4.40%): it should be faster in real time too. 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.98% instructions, same-arm spread 0.013%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.98%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy79,850,008,56079,846,397,96611,4186,993,18621,95514,521
optimized78,263,425,50478,273,439,47511,4186,854,82920,41212,705
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-4.40% — cycles-faster (same-arm spread 1.47%)faster
IPC (instructions per cycle, higher is better)0.882 / 0.862same
backend stall / frontend stall (share of cycles)17.1% / 18.9%  ·  48.8% / 47.7%less waiting
L1D / L2D refills per 1k instructions (cache misses)16.81 / 16.97  ·  13.55 / 13.54same
branch mispredicts per 1k instructions5.014 / 4.948same
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/it30-parity-20261003-020436-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: 44 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 mingate check: 7 mingate focused: 16 mingate parity: 5 min
planner 7mexecutor 44mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3mgate check 7mgate focused 16mgate parity 5m
executor: 18,421,720 in / 26,241 out tokensplanner: 2,534,695 in / 9,510 out tokensreviewer: 23,978 in / 1,128 out tokens

Mechanism. At game/layers.rs:566 and :639, turn/step expiry and untap arming acquire mutable access to every object before inspecting its permissions. Discover affected IDs through immutable iteration, then acquire mutable access only when an existing permission will expire or be armed.

Evidence. docs/profiles/uprof-20261002-1125/w0-owners-all.txt attributes 1.4% CPU directly to prune_casting_permissions_at; w0-owners-alloc.txt attributes 0.5% allocation-family CPU to that owner, overlapping the first number. ObjectStore::iter_mut calls Arc::make_mut for every object. These captures precede some loop changes. The indexed xn5.5 section at memo L1339 covers host-departure pruning, a separate site with a neutral whole-engine result.

Counter and kill threshold. Existing prune_casting_permissions_at profile rows: 1.4% nearest-owner CPU and overlapping 0.5% allocation CPU. Expected reduction: 0.5–1.0% instructions per action at 4,000 actions; this is an unmeasured hypothesis. Untap arming has no separate measured share and receives no additional credit.

Invariant. Use CastingPermission::lifetime and permission_duration_expires_at unchanged. Preserve retained permission order, keyed-player selection, untap arming before expiry, and all fingerprints. Permanent explicit-arm regressions must compare every expiry seam, matching and nonmatching players, permanent and host-bound permissions, and fork isolation; no-op expiry must preserve object_ptr sharing.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol7m 57s02,534,695 / 9,510
executorcodex / gpt-6-luna44m 24s018,421,720 / 26,241
reviewercodex / gpt-6.1-sol0m 51s023,978 / 1,128

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it30-build
ir1kpass0Ir -2.97% (threshold -1%), same-arm spread 0.0076% | optimized 20,356,212,013 vs legacy 20,978,842,524 instructions; fingerprints match: True
ir4kpass0Ir -1.98% (threshold -1%), same-arm spread 0.0136% | optimized 78,266,561,980 vs legacy 79,850,992,760 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 it30-parity

Write-up: 2026-10-03 - Loop iteration 30: Avoid unchanged casting-permission expiry writes (retained)

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

Automated loop result on homelab (aarch64). Switch PHASE_PERMISSION_EXPIRY_WRITES_LEGACY, mechanism class copy. Mechanism: At game/layers.rs:566 and :639, turn/step expiry and untap arming acquire mutable access to every object before inspecting its permissions. Discover affected IDs through immutable iteration, then acquire mutable access only when an existing permission will expire or be armed. Invariant: Use CastingPermission::lifetime and permission_duration_expires_at unchanged. Preserve retained permission order, keyed-player selection, untap arming before expiry, and all fingerprints. Permanent explicit-arm regressions must compare every expiry seam, matching and nonmatching players, permanent and host-bound permissions, and fork isolation; no-op expiry must preserve object_ptr sharing.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -2.97% (threshold -1%), same-arm spread 0.0076%
ir4kyesIr -1.98% (threshold -1%), same-arm spread 0.0136%
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:12 · read-only · refreshes every 30 s