MTGBench improvement loop

Overview · Experiment index

Iteration 33: Build replacement buckets only for the current event

state rejected — failed gate focused
switch PHASE_REPLACEMENT_EVENT_BUCKET_LEGACY · branch loop/it33 · base 4ec0b9ef1 · candidate 1329f0600 · took 4h 37m

Results

Verdict: NO GAIN: 0.05% MORE instructions. Cycles moved -0.67%, within this machine's noise (±5.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.05% instructions, same-arm spread 0.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0+0.05%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,573,060,14721,572,283,5304,0005,393,1682,6022,331
optimized21,583,207,63021,584,306,2134,0005,395,9392,4562,520
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.67% — cycles-neutral (same-arm spread 4.96%)same within noise
IPC (instructions per cycle, higher is better)1.012 / 1.010same
backend stall / frontend stall (share of cycles)22.7% / 19.0%  ·  38.2% / 42.2%more waiting
L1D / L2D refills per 1k instructions (cache misses)13.09 / 12.98  ·  11.65 / 11.15same
branch mispredicts per 1k instructions5.789 / 5.620same
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.35% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved +1.11%, within this machine's noise (±3.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.35% instructions, same-arm spread 0.010%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.35%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,539,470,59977,531,935,38511,4186,790,65517,98811,898
optimized77,268,145,78077,267,753,27211,4186,767,20519,24512,673
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+1.11% — cycles-neutral (same-arm spread 2.96%)same within noise
IPC (instructions per cycle, higher is better)0.906 / 0.910same
backend stall / frontend stall (share of cycles)26.8% / 27.2%  ·  37.7% / 37.1%same
L1D / L2D refills per 1k instructions (cache misses)17.64 / 17.49  ·  13.97 / 13.73same
branch mispredicts per 1k instructions5.309 / 5.093same
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.

Where the time went

planner: 8 minexecutor: 65 minreviewer: 1 minexecutor: 14 minreviewer: 1 minexecutor: 37 minreviewer: 1 mingate fmt: 0 mingate build: 19 mingate ir1k: 1 mingate ir4k: 3 mingate check: 12 mingate focused: 25 minnot attributed: 86 min
planner 8mexecutor 65mreviewer 1mexecutor 14mreviewer 1mexecutor 37mreviewer 1mgate fmt 0mgate build 19mgate ir1k 1mgate ir4k 3mgate check 12mgate focused 25mnot attributed 86m
executor: 22,806,633 in / 48,214 out tokensplanner: 2,638,662 in / 10,316 out tokensreviewer: 76,086 in / 4,248 out tokens

Mechanism. At game/replacement.rs::rebuild_replacement_index, enumerate active replacements in the existing order but insert only definitions whose event key belongs to replacement_event_keys_for_event(proposed). Keep the current persistent bucket representation and original ordinals. Record which keys the partial index covers; consultations for uncovered keys use the existing direct scan.

Evidence. docs/stage0-decision-memo.md:L5379 (xn5.69) measured bucket assembly at 1.141%/1.207% of contract+apply and assembly plus drop plus clone at 1.302%/1.370%. The newer docs/profiles/perf-20261002-1221/summary.md shows replacement preparation at 2.2–3.7% across five windows. These bound the family, not the fraction attributable to irrelevant buckets; the profile predates the later loop candidates.

Counter and kill threshold. Existing replacement_index_bucket_assembly_ns, replacement_index_bucket_drop_ns and replacement_index_clone_ns; xn5.69's representation-sensitive ceiling is approximately 1.3%. Expected instruction reduction: 0.3–0.7% per action at 4,000 actions, an unmeasured forecast. Allocation savings may exceed the instruction result.

Invariant. Ordered replacement candidates, proposed-event transitions, prompts and all three fingerprints remain identical. Preserve enumeration ordinals before filtering, virtual and floating candidates, liminal self-replacements, and rebuilding at every pipeline entry. An uncovered event key must trigger the direct scan, never imply absence.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 51s02,638,662 / 10,316
executorcodex / gpt-6-luna1h 5m08,350,665 / 18,280
reviewercodex / gpt-6.1-sol1m 1s025,362 / 1,563
executorcodex / gpt-6-luna1356h 15m /
executorcodex / gpt-6-luna14m 14s04,965,642 / 7,842
reviewercodex / gpt-6.1-sol1m 10s025,362 / 1,256
executorcodex / gpt-6-luna37m 0s09,490,326 / 22,092
reviewercodex / gpt-6.1-sol1m 17s025,362 / 1,429

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it33-build
ir1kpass0Ir +0.05% within +/-1%, same-arm spread 0.0092% | optimized 21,583,998,221 vs legacy 21,572,141,299 instructions; fingerprints match: True
ir4kFAIL0Ir -0.35% within +/-1%, same-arm spread 0.0097% | optimized 77,267,646,231 vs legacy 77,536,256,678 instructions; fingerprints match: True
checkpass0
focusedFAIL101

Write-up: 2026-10-03 - Loop iteration 33: Build replacement buckets only for the current event (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_REPLACEMENT_EVENT_BUCKET_LEGACY, mechanism class allocation. Mechanism: At game/replacement.rs::rebuild_replacement_index, enumerate active replacements in the existing order but insert only definitions whose event key belongs to replacement_event_keys_for_event(proposed). Keep the current persistent bucket representation and original ordinals. Record which keys the partial index covers; consultations for uncovered keys use the existing direct scan. Invariant: Ordered replacement candidates, proposed-event transitions, prompts and all three fingerprints remain identical. Preserve enumeration ordinals before filtering, virtual and floating candidates, liminal self-replacements, and rebuilding at every pipeline entry. An uncovered event key must trigger the direct scan, never imply absence.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr +0.05% within +/-1%, same-arm spread 0.0092%
ir4kmarginal: workstation checkIr -0.35% within +/-1%, same-arm spread 0.0097%
checkyes
focusedNO

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:09 · read-only · refreshes every 30 s