MTGBench improvement loop

Overview · Experiment index

Iteration 31: Skip lookups and class traversal for empty recipient-index buckets

state confirm-pending — gate ir4k: marginal instruction reduction (compute); the workstation wall-clock decides
switch PHASE_RECIPIENT_BUCKET_EMPTINESS_LEGACY · branch loop/it31 · base 4ec0b9ef1 · candidate d416be2f6 · took 1h 39m

Results

Verdict: TOO SMALL: only 0.20% fewer instructions, under the 0.3% floor. Cycles moved +0.73%, within this machine's noise (±2.4%): 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.20% instructions, same-arm spread 0.022%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.20%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,551,152,62021,547,599,8354,0005,387,3442,3722,219
optimized21,507,924,95121,503,093,2584,0005,376,3772,6142,464
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.73% — cycles-neutral (same-arm spread 2.44%)same within noise
IPC (instructions per cycle, higher is better)1.031 / 1.037same
backend stall / frontend stall (share of cycles)20.1% / 19.6%  ·  41.0% / 40.7%same
L1D / L2D refills per 1k instructions (cache misses)13.03 / 13.00  ·  11.25 / 11.14same
branch mispredicts per 1k instructions5.640 / 5.571same
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.52% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved +0.86%, within this machine's noise (±2.0%): 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.52% instructions, same-arm spread 0.019%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.52%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,446,512,72977,452,393,71411,4186,783,10219,86212,865
optimized77,041,714,29677,056,502,38311,4186,748,03919,46112,943
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.86% — cycles-neutral (same-arm spread 1.97%)same within noise
IPC (instructions per cycle, higher is better)0.887 / 0.901same
backend stall / frontend stall (share of cycles)23.3% / 24.2%  ·  42.3% / 40.9%same
L1D / L2D refills per 1k instructions (cache misses)17.51 / 17.51  ·  13.98 / 13.90same
branch mispredicts per 1k instructions5.169 / 5.146same
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/it31-parity-20261003-034400-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 minexecutor: 3 minreviewer: 0 mingate fmt: 0 mingate build: 10 mingate ir1k: 1 mingate ir4k: 3 mingate check: 6 mingate focused: 14 mingate parity: 4 min
planner 7mexecutor 45mexecutor 3mreviewer 0mgate fmt 0mgate build 10mgate ir1k 1mgate ir4k 3mgate check 6mgate focused 14mgate parity 4m
executor: 31,404,376 in / 54,811 out tokensplanner: 2,302,353 in / 9,146 out tokensreviewer: 23,610 in / 258 out tokens

Mechanism. In OffZoneRecipientIndex::may_have_candidates and narrow_candidates (static_source_index.rs:115,148), check each bucket family's emptiness before probing it. Empty by_core and by_subtype maps require no traversal of the object's types or subtype strings; an empty by_permanent bucket requires no permanent-type scan. Preserve merging, sorting and deduplication for populated buckets.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, references bench/reports/uprof-xn565-20260923-owners-all.txt: may_have_candidates owns 0.9% of process CPU and narrow_candidates owns 0.8%. These are component ceilings; the empty-bucket fraction is unmeasured. xn5.31.1 at L2996 confirms that borrowed subtype lookup and allocation-free presence queries are already retained; this removes remaining empty-map work.

Counter and kill threshold. Existing xn5.67 owner rows: may_have_candidates 0.9%, narrow_candidates 0.8%. Expected instruction reduction: 0.4–0.9% per action at 4,000 actions, an estimate requiring the loop's A/B gate.

Invariant. An empty bucket cannot contribute a candidate. Preserve the exact presence verdict and ordered candidate vector, including fallback handling. Add permanent differential tests covering an entirely empty index, each independently populated bucket family, mixed types, duplicate candidates and fallback-only indexes.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol7m 11s02,302,353 / 9,146
executorcodex / gpt-6-luna45m 40s015,257,388 / 24,943
executorcodex / gpt-6-luna3m 45s016,146,988 / 29,868
reviewercodex / gpt-6.1-sol0m 14s023,610 / 258

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it31-build
ir1kpass0Ir -0.19% within +/-1%, same-arm spread 0.0343% | optimized 21,505,777,323 vs legacy 21,547,505,205 instructions; fingerprints match: True
ir4kFAIL0Ir -0.51% within +/-1%, same-arm spread 0.0367% | optimized 77,056,074,956 vs legacy 77,452,886,070 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 it31-parity

Write-up: 2026-10-03 - Loop iteration 31: Skip lookups and class traversal for empty recipient-index buckets (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_RECIPIENT_BUCKET_EMPTINESS_LEGACY, mechanism class compute. Mechanism: In OffZoneRecipientIndex::may_have_candidates and narrow_candidates (static_source_index.rs:115,148), check each bucket family's emptiness before probing it. Empty by_core and by_subtype maps require no traversal of the object's types or subtype strings; an empty by_permanent bucket requires no permanent-type scan. Preserve merging, sorting and deduplication for populated buckets. Invariant: An empty bucket cannot contribute a candidate. Preserve the exact presence verdict and ordered candidate vector, including fallback handling. Add permanent differential tests covering an entirely empty index, each independently populated bucket family, mixed types, duplicate candidates and fallback-only indexes.

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