MTGBench improvement loop

Overview · Experiment index

Iteration 8: Reuse deduplicated layer recipient IDs for single-zone effects

state retained — instruction-count retained; awaiting workstation wall-clock confirmation
switch PHASE_LAYER_RECIPIENT_IDS_LEGACY · branch loop/it8 · base 4ec0b9ef1 · candidate 4a27f20e2 · took 14h 13m

Results

Verdict: TOO SMALL: only 0.20% fewer instructions, under the 0.3% floor. The final word is always the PC wall-clock.
Gate: 1,000 actions (screen) — -0.20% instructions, same-arm spread 0.024%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.20%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,038,896,84622,039,534,2964,0005,509,8042,5852,340
optimized21,997,555,30121,992,301,7884,0005,498,7322,8112,735
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.
Verdict: GOOD: 1.29% fewer instructions, above the 1% bar. The final word is always the PC wall-clock.
Gate: 4,000 actions (verdict) — -1.29% instructions, same-arm spread 0.027%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.29%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy80,729,379,83180,750,972,68911,4187,071,30622,49014,186
optimized79,700,404,64679,692,301,40011,4186,979,88720,06913,499
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.
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/it8-parity-20261001-135028-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: 8 minexecutor: 50 minreviewer: 0 minexecutor: 52 minreviewer: 1 mingate fmt: 0 mingate ir1k: 0 mingate ir4k: 2 mingate check: 12 mingate focused: 24 mingate build: 12 mingate parity: 5 minnot attributed: 682 min
planner 8mexecutor 50mreviewer 0mexecutor 52mreviewer 1mgate fmt 0mgate ir1k 0mgate ir4k 2mgate check 12mgate focused 24mgate build 12mgate parity 5mnot attributed 682m
executor: 28,354,831 in / 45,691 out tokensplanner: 2,453,126 in / 9,353 out tokensreviewer: 43,956 in / 2,753 out tokens

Mechanism. At layers.rs:82, effect_candidate_ids rebuilds a HashSet and Vec for every effect, although LayerZoneObjectCache already stores the zone's IDs. Deduplicate each cached zone vector once, preserving first-occurrence order. Return a borrowed slice for single-zone filters and retain the existing union algorithm for multi-zone filters.

Evidence. xn5.67, docs/stage0-decision-memo.md:4904, is the latest indexed CPU profile. Its accompanying bench/reports/uprof-xn565-20260923-owners-alloc.txt attributes 0.4% of process CPU directly to allocation beneath layers::effect_candidate_ids. The containing apply_continuous_effect_filtered family measured 2.86% inclusive CPU. These overlap; the latter is only a ceiling. The profile predates subsequent retained changes, so neither share is a current speedup prediction.

Counter and kill threshold. Existing xn5.67 allocation-owner row: layers::effect_candidate_ids, 0.4% process CPU. Hashing and vector construction add unseparated work. Expected 4,000-action instruction reduction: 0.4–0.9% per action, an unmeasured forecast likely to enter the marginal band. Apply the loop's existing tiers unchanged.

Invariant. Candidate IDs retain exactly the same order and stable deduplication, including duplicated IDs in a zone vector. Cache only raw IDs; evaluate filters and conditions against live state for every effect. A permanent differential regression must compare both paths for single-zone, overlapping multi-zone, duplicate-ID and resolving-stack fixtures, plus a keyword grant that changes a later layer's filter result.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 2s02,453,126 / 9,353
executorcodex / gpt-6-luna50m 8s09,543,594 / 18,820
reviewercodex / gpt-6.1-sol0m 56s020,497 / 1,271
executorcodex / gpt-6-luna52m 8s018,811,237 / 26,871
reviewercodex / gpt-6.1-sol1m 12s023,459 / 1,482

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
ir1kpass0Ir -0.20% within +/-1%, same-arm spread 0.0239% | optimized 21,994,928,544 vs legacy 22,039,215,571 instructions; fingerprints match: True
ir4kpass0Ir -1.29% (threshold -1%), same-arm spread 0.0267% | optimized 79,696,353,023 vs legacy 80,740,176,260 instructions; fingerprints match: True
checkpass0
focusedpass0
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it8-build
paritypass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode parity -Seeds 1,2,3,5,7,11,13 -Actions 1000 -CargoProfile bench-fast-inc -Label it8-parity

Write-up: 2026-10-01 - Loop iteration 8: Reuse deduplicated layer recipient IDs for single-zone effects (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_LAYER_RECIPIENT_IDS_LEGACY, mechanism class allocation. Mechanism: At layers.rs:82, effect_candidate_ids rebuilds a HashSet and Vec for every effect, although LayerZoneObjectCache already stores the zone's IDs. Deduplicate each cached zone vector once, preserving first-occurrence order. Return a borrowed slice for single-zone filters and retain the existing union algorithm for multi-zone filters. Invariant: Candidate IDs retain exactly the same order and stable deduplication, including duplicated IDs in a zone vector. Cache only raw IDs; evaluate filters and conditions against live state for every effect. A permanent differential regression must compare both paths for single-zone, overlapping multi-zone, duplicate-ID and resolving-stack fixtures, plus a keyword grant that changes a later layer's filter result.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.20% within +/-1%, same-arm spread 0.0239%
ir4kyesIr -1.29% (threshold -1%), same-arm spread 0.0267%
checkyes
focusedyes
parityNOpwsh -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.

Write-up: 2026-10-01 - Loop iteration 8: Reuse deduplicated layer recipient IDs for single-zone effects (retained)

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

Automated loop result on homelab (aarch64). Switch PHASE_LAYER_RECIPIENT_IDS_LEGACY, mechanism class allocation. Mechanism: At layers.rs:82, effect_candidate_ids rebuilds a HashSet and Vec for every effect, although LayerZoneObjectCache already stores the zone's IDs. Deduplicate each cached zone vector once, preserving first-occurrence order. Return a borrowed slice for single-zone filters and retain the existing union algorithm for multi-zone filters. Invariant: Candidate IDs retain exactly the same order and stable deduplication, including duplicated IDs in a zone vector. Cache only raw IDs; evaluate filters and conditions against live state for every effect. A permanent differential regression must compare both paths for single-zone, overlapping multi-zone, duplicate-ID and resolving-stack fixtures, plus a keyword grant that changes a later layer's filter result.

gatepasseddetail
fmtyescargo fmt --all -- --check
ir1kyesIr -0.20% within +/-1%, same-arm spread 0.0239%
ir4kyesIr -1.29% (threshold -1%), same-arm spread 0.0267%
checkyes
focusedyes
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
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:08 · read-only · refreshes every 30 s