MTGBench improvement loop

Overview · Experiment index

Iteration 47: Use cheaper hashing for replacement-event buckets

state confirm-pending — gate ir4k: marginal instruction reduction (compute); the workstation wall-clock decides
switch PHASE_REPLACEMENT_BUCKET_HASH_LEGACY · branch loop/it47 · base 4ec0b9ef1 · candidate 3005d6315 · took 2h 54m

Results

Verdict: MARGINAL: 0.40% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved +0.05%, within this machine's noise (±8.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: 1,000 actions (screen) — -0.40% instructions, same-arm spread 0.017%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.40%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,548,926,72521,545,360,3254,0005,386,7862,4302,548
optimized21,463,380,17021,459,803,6354,0005,365,3983,8283,560
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.05% — cycles-neutral (same-arm spread 8.00%)same within noise
IPC (instructions per cycle, higher is better)0.996 / 1.016same
backend stall / frontend stall (share of cycles)17.8% / 17.3%  ·  43.4% / 43.0%same
L1D / L2D refills per 1k instructions (cache misses)13.21 / 13.06  ·  11.26 / 11.20same
branch mispredicts per 1k instructions5.930 / 5.849same
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.46% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -0.11%, within this machine's noise (±2.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.46% instructions, same-arm spread 0.032%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.46%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,426,279,32077,437,196,94111,4186,781,55020,16012,805
optimized77,085,060,46077,060,666,44411,4186,750,11920,20313,495
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.11% — cycles-neutral (same-arm spread 2.20%)same within noise
IPC (instructions per cycle, higher is better)0.884 / 0.886same
backend stall / frontend stall (share of cycles)18.4% / 18.7%  ·  47.0% / 46.6%same
L1D / L2D refills per 1k instructions (cache misses)17.65 / 17.62  ·  13.80 / 13.85same
branch mispredicts per 1k instructions5.107 / 5.165same
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/it47-parity-20261004-065002-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: 38 minreviewer: 0 mingate fmt: 0 mingate build: 27 mingate ir1k: 1 mingate ir4k: 3 mingate check: 30 mingate focused: 56 mingate parity: 5 min
planner 8mexecutor 38mreviewer 0mgate fmt 0mgate build 27mgate ir1k 1mgate ir4k 3mgate check 30mgate focused 56mgate parity 5m
executor: 4,179,783 in / 12,506 out tokensplanner: 2,548,429 in / 10,365 out tokensreviewer: 21,388 in / 1,308 out tokens

Mechanism. Replace RandomState hashing with FxBuildHasher only for ReplacementIndex.by_event. Keep the existing persistent map, vectors, full rebuild cadence, and ordinal-based candidate ordering. A private bucket wrapper carries both map types so the legacy arm retains the original implementation.

Evidence. xn5.69, docs/stage0-decision-memo.md:L5379, measured bucket assembly at 97.717/92.427 ms, or 1.141%/1.207% of contract+apply for seeds 91/42. xn5.67:L4904 also recorded sip::write at 0.110 seconds. Hashing's exclusive contribution inside bucket assembly is unmeasured; the assembly share is a ceiling, not a predicted saving.

Counter and kill threshold. Existing replacement_index_bucket_assembly_ns bounds the affected build region. Expected instruction reduction: 0.3–0.7% per action, an unverified marginal-band hypothesis. The loop's standard gates decide retention.

Invariant. Hash choice changes lookup representation, not key equality or bucket contents. Consults restore source order using stored ordinals and re-read live replacement predicates. Permanent differential tests must compare ordered candidates across both hashers, including multiple event keys, distinct Other(String) keys, and same-revision replacement mutations.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 30s02,548,429 / 10,365
executorcodex / gpt-6-luna38m 55s04,179,783 / 12,506
reviewercodex / gpt-6.1-sol0m 57s021,388 / 1,308

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it47-build
ir1kpass0Ir -0.40% within +/-1%, same-arm spread 0.0168% | optimized 21,461,517,395 vs legacy 21,547,758,677 instructions; fingerprints match: True
ir4kFAIL0Ir -0.46% within +/-1%, same-arm spread 0.0316% | optimized 77,076,267,733 vs legacy 77,430,187,138 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 it47-parity

Write-up: 2026-10-04 - Loop iteration 47: Use cheaper hashing for replacement-event buckets (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_REPLACEMENT_BUCKET_HASH_LEGACY, mechanism class compute. Mechanism: Replace RandomState hashing with FxBuildHasher only for ReplacementIndex.by_event. Keep the existing persistent map, vectors, full rebuild cadence, and ordinal-based candidate ordering. A private bucket wrapper carries both map types so the legacy arm retains the original implementation. Invariant: Hash choice changes lookup representation, not key equality or bucket contents. Consults restore source order using stored ordinals and re-read live replacement predicates. Permanent differential tests must compare ordered candidates across both hashers, including multiple event keys, distinct Other(String) keys, and same-revision replacement mutations.

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