MTGBench improvement loop

Overview · Experiment index

Iteration 50: Build trigger-index buckets in a transient hash map

state rejected — failed gate ir4k
switch PHASE_TRIGGER_REBUILD_TRANSIENT_LEGACY · branch loop/it50 · base 4ec0b9ef1 · candidate 834ce9e10 · took 1h 5m

Results

Verdict: NO GAIN: 0.01% MORE instructions. Cycles moved -2.73%, within this machine's noise (±3.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: 1,000 actions (screen) — +0.01% instructions, same-arm spread 0.015%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0+0.01%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,555,047,99121,558,208,9824,0005,389,1573,5102,767
optimized21,557,496,00721,559,149,6674,0005,389,5812,4342,322
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-2.73% — cycles-neutral (same-arm spread 3.20%)same within noise
IPC (instructions per cycle, higher is better)1.026 / 1.010same
backend stall / frontend stall (share of cycles)17.6% / 17.1%  ·  42.2% / 43.3%same
L1D / L2D refills per 1k instructions (cache misses)12.95 / 12.99  ·  11.30 / 11.36same
branch mispredicts per 1k instructions5.578 / 5.795same
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: NO GAIN: 0.02% MORE instructions. Cycles moved +0.63%, within this machine's noise (±4.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: 4,000 actions (verdict) — +0.02% instructions, same-arm spread 0.010%, equal work: yes, fingerprints match: yes
Gate FAILED: the harness refused this A/B (exit 0); see the write-up below. These counts are not a valid measurement.
-1% retain-0.3% kill0+0.02%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,471,683,00877,478,941,27011,4186,785,36617,31711,359
optimized77,489,690,25677,497,662,49311,4186,786,97518,99713,065
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.63% — cycles-neutral (same-arm spread 4.36%)same within noise
IPC (instructions per cycle, higher is better)0.901 / 0.900same
backend stall / frontend stall (share of cycles)24.1% / 21.7%  ·  40.0% / 42.8%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.52 / 17.50  ·  14.05 / 13.97same
branch mispredicts per 1k instructions5.235 / 5.026same
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: 41 minreviewer: 0 mingate fmt: 0 mingate build: 8 mingate ir1k: 1 mingate ir4k: 3 min
planner 8mexecutor 41mreviewer 0mgate fmt 0mgate build 8mgate ir1k 1mgate ir4k 3m
executor: 11,745,112 in / 21,090 out tokensplanner: 2,750,014 in / 8,942 out tokensreviewer: 23,645 in / 802 out tokens

Mechanism. In trigger_index.rs:1136, accumulate rebuild buckets in std::collections::HashMap<TriggerEventKey, SmallVec<[ObjectId; 4]>>, then convert once into the existing im::HashMap. This replaces repeated persistent-map entry traversals during reconstruction while preserving the stored representation and incremental add/remove paths.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4947, attributes 0.80% inclusive process CPU to TriggerIndex::rebuild_from_battlefield. That bounds the whole rebuild, not bucket insertion alone, and predates the pending trigger-index borrowing change; the remaining opportunity is smaller.

Counter and kill threshold. Existing xn5.67 TriggerIndex::rebuild_from_battlefield profile row: 0.80% inclusive CPU. Expected instruction reduction: 0.3–0.6% per action at 4,000 actions, an unverified marginal-band expectation.

Invariant. Every key retains the same ordered, duplicate-free object IDs, and unclassified retains identical contents and order. Preserve keys_from_trigger_def, synthetic-keyword admission, phased-out exclusion and duplicate handling. Compare complete buckets and event candidate lists between both rebuild implementations.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 31s02,750,014 / 8,942
executorcodex / gpt-6-luna41m 40s011,745,112 / 21,090
reviewercodex / gpt-6.1-sol0m 47s023,645 / 802

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it50-build
ir1kpass0Ir -+0.00% within +/-1%, same-arm spread 0.0232% | optimized 21,557,549,521 vs legacy 21,557,765,485 instructions; fingerprints match: True
ir4kFAIL0Ir +0.02% within +/-1%, same-arm spread 0.0187% | optimized 77,494,554,255 vs legacy 77,478,921,245 instructions; fingerprints match: True

Write-up: 2026-10-04 - Loop iteration 50: Build trigger-index buckets in a transient hash map (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_TRIGGER_REBUILD_TRANSIENT_LEGACY, mechanism class compute. Mechanism: In trigger_index.rs:1136, accumulate rebuild buckets in std::collections::HashMap<TriggerEventKey, SmallVec<[ObjectId; 4]>>, then convert once into the existing im::HashMap. This replaces repeated persistent-map entry traversals during reconstruction while preserving the stored representation and incremental add/remove paths. Invariant: Every key retains the same ordered, duplicate-free object IDs, and unclassified retains identical contents and order. Preserve keys_from_trigger_def, synthetic-keyword admission, phased-out exclusion and duplicate handling. Compare complete buckets and event candidate lists between both rebuild implementations.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -+0.00% within +/-1%, same-arm spread 0.0232%
ir4kNOIr +0.02% within +/-1%, same-arm spread 0.0187%

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