MTGBench improvement loop

Overview · Experiment index

Iteration 13: Capture pairing cleanup candidates once per full layer evaluation

state confirm-pending — gate ir4k: marginal instruction reduction (compute); the workstation wall-clock decides
switch PHASE_LAYER_PAIR_CANDIDATES_LEGACY · branch loop/it13 · base 4ec0b9ef1 · candidate cc5b3495f · took 2h 8m

Results

Verdict: MARGINAL: 0.53% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -3.59%, within this machine's noise (±6.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) — -0.53% instructions, same-arm spread 0.025%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.53%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,086,280,95622,091,850,1864,0005,522,2663,8783,643
optimized21,971,955,23221,973,564,8474,0005,493,1902,6712,522
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-3.59% — cycles-neutral (same-arm spread 6.90%)same within noise
IPC (instructions per cycle, higher is better)1.014 / 0.981same
backend stall / frontend stall (share of cycles)17.6% / 18.3%  ·  42.8% / 43.2%same
L1D / L2D refills per 1k instructions (cache misses)12.63 / 12.72  ·  11.10 / 11.44same
branch mispredicts per 1k instructions5.620 / 5.901same
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.63% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -3.54%, within this machine's noise (±5.2%): 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.63% instructions, same-arm spread 0.008%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.63%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,013,330,42581,020,066,15611,4187,095,52420,40312,793
optimized80,505,444,75980,507,987,43111,4187,050,86020,07513,776
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-3.54% — cycles-neutral (same-arm spread 5.23%)same within noise
IPC (instructions per cycle, higher is better)0.893 / 0.884same
backend stall / frontend stall (share of cycles)20.8% / 20.4%  ·  43.9% / 44.7%same
L1D / L2D refills per 1k instructions (cache misses)16.74 / 16.73  ·  13.50 / 13.44same
branch mispredicts per 1k instructions5.070 / 5.154same
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/it13-parity-20261001-191359-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: 45 minreviewer: 0 minexecutor: 31 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 mingate check: 7 mingate focused: 15 mingate parity: 5 min
planner 7mexecutor 45mreviewer 0mexecutor 31mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3mgate check 7mgate focused 15mgate parity 5m
executor: 11,540,280 in / 28,100 out tokensplanner: 1,840,630 in / 8,932 out tokensreviewer: 42,049 in / 1,654 out tokens

Mechanism. In layers.rs:3084 and :3243, cleanup_invalid_pairs repeatedly walks the entire object store after Control, Type and the final pass. Capture the ordered IDs with paired_with present once before resetting characteristics, then run the existing validation and break logic over that list at every original checkpoint. Keep the public standalone cleanup function unchanged.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, attributes 0.65% inclusive process CPU to cleanup_invalid_pairs under evaluate_layers. bench/reports/uprof-xn565-20260923-owners-all.txt independently reports approximately 0.6% directly owned CPU. Source inspection confirms multiple full-store scans per evaluation; their individual shares are not separately measured.

Counter and kill threshold. Existing xn5.67 cleanup_invalid_pairs profile row: 0.65% inclusive CPU. Expected reduction: 0.3–0.5% instructions/action at 4,000 actions, an estimate rather than a measurement; likely marginal under the loop's unchanged tiers.

Invariant. Preserve cleanup checkpoint timing, candidate order, broken pairs, layer dirtiness and final characteristics. Pair creation occurs through pair_objects outside layer evaluation; layer application can only retain or remove existing pair links. Capture candidates across all zones, including malformed off-zone fixtures, and re-read their current links at each checkpoint.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol7m 43s01,840,630 / 8,932
executorcodex / gpt-6-luna45m 24s05,767,618 / 15,457
reviewercodex / gpt-6.1-sol0m 39s020,702 / 831
executorcodex / gpt-6-luna31m 22s05,772,662 / 12,643
reviewercodex / gpt-6.1-sol0m 40s021,347 / 823

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it13-build
ir1kpass0Ir -0.52% within +/-1%, same-arm spread 0.0252% | optimized 21,973,885,565 vs legacy 22,089,388,936 instructions; fingerprints match: True
ir4kFAIL0Ir -0.63% within +/-1%, same-arm spread 0.0230% | optimized 80,512,474,925 vs legacy 81,019,584,699 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 it13-parity

Write-up: 2026-10-01 - Loop iteration 13: Capture pairing cleanup candidates once per full layer evaluation (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_LAYER_PAIR_CANDIDATES_LEGACY, mechanism class compute. Mechanism: In layers.rs:3084 and :3243, cleanup_invalid_pairs repeatedly walks the entire object store after Control, Type and the final pass. Capture the ordered IDs with paired_with present once before resetting characteristics, then run the existing validation and break logic over that list at every original checkpoint. Keep the public standalone cleanup function unchanged. Invariant: Preserve cleanup checkpoint timing, candidate order, broken pairs, layer dirtiness and final characteristics. Pair creation occurs through pair_objects outside layer evaluation; layer application can only retain or remove existing pair links. Capture candidates across all zones, including malformed off-zone fixtures, and re-read their current links at each checkpoint.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.52% within +/-1%, same-arm spread 0.0252%
ir4kmarginal: workstation checkIr -0.63% within +/-1%, same-arm spread 0.0230%
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:15 · read-only · refreshes every 30 s