MTGBench improvement loop

Overview · Experiment index

Iteration 12: Borrow trigger definitions during index rebuilds

state confirm-pending — gate ir4k: marginal instruction reduction (copy); the workstation wall-clock decides
switch PHASE_TRIGGER_INDEX_BORROW_LEGACY · branch loop/it12 · base 4ec0b9ef1 · candidate 3821cad8d · took 3h 41m

Results

Verdict: TOO SMALL: only 0.21% fewer instructions, under the 0.3% floor. Cycles moved -2.56%, 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.21% instructions, same-arm spread 0.014%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.21%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,782,201,09521,785,284,2914,0005,445,9362,4172,272
optimized21,738,927,34221,735,805,8624,0005,434,3422,6302,468
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.56% — cycles-neutral (same-arm spread 6.92%)same within noise
IPC (instructions per cycle, higher is better)1.026 / 1.009same
backend stall / frontend stall (share of cycles)16.3% / 16.3%  ·  44.1% / 44.1%same
L1D / L2D refills per 1k instructions (cache misses)12.82 / 12.86  ·  10.90 / 10.90same
branch mispredicts per 1k instructions5.630 / 5.407same
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.57%, within this machine's noise (±3.1%): 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.006%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.52%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,430,298,06278,425,270,63811,4186,868,78519,30213,055
optimized78,022,092,75978,019,557,81711,4186,833,14318,96612,122
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.57% — cycles-neutral (same-arm spread 3.07%)same within noise
IPC (instructions per cycle, higher is better)0.910 / 0.903same
backend stall / frontend stall (share of cycles)22.1% / 20.3%  ·  41.9% / 44.1%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.29 / 17.29  ·  13.55 / 13.64same
branch mispredicts per 1k instructions5.086 / 5.328same
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/it12-parity-20261001-170600-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: 13 minexecutor: 32 minreviewer: 0 mingate fmt: 0 mingate build: 7 mingate ir1k: 1 mingate ir4k: 3 mingate check: 6 mingate focused: 13 mingate parity: 5 minnot attributed: 136 min
planner 13mexecutor 32mreviewer 0mgate fmt 0mgate build 7mgate ir1k 1mgate ir4k 3mgate check 6mgate focused 13mgate parity 5mnot attributed 136m
executor: 4,331,363 in / 12,309 out tokensplanner: 3,965,785 in / 14,361 out tokensreviewer: 21,059 in / 660 out tokens

Mechanism. At game/trigger_index.rs:1136, rebuild_from_battlefield deep-clones each materialized TriggerDefinition into a SmallVec before classifying it. Add a private registration helper accepting borrowed definitions and use it during rebuilding and reindex_object_triggers. Preserve the public slice-based add API.

Evidence. docs/stage0-decision-memo.md:L4904, xn5.67, attributes 0.80% inclusive process CPU to TriggerIndex::rebuild_from_battlefield. This is the narrowest measured envelope among these candidates; the clone-only fraction is unmeasured. xn5.71 at L5434 retained sharing of captured TriggerSourceContext entries, which is a separate clone site and provides no additional credit here. The profile predates subsequent retained changes.

Counter and kill threshold. Existing xn5.67 profile row: TriggerIndex::rebuild_from_battlefield, 0.80% inclusive CPU. Expected whole-engine instruction reduction per action: 0.3–0.6%, an uncertain forecast. Copy and allocation savings may appear marginal in instruction counts.

Invariant. Classification reads definitions without modifying them. Borrowing must preserve registration order, bucket contents, duplicate suppression, synthetic-keyword routing and materialized occurrence identities. Permanently compare complete indices and ordered event candidates between both implementations, including granted/removed triggers, phased-out objects and rebuilding after deserialization.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol1396h 47m /
plannercodex / gpt-6.1-sol13m 0s03,965,785 / 14,361
executorcodex / gpt-6-luna32m 52s04,331,363 / 12,309
reviewercodex / gpt-6.1-sol0m 35s021,059 / 660

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it12-build
ir1kpass0Ir -0.22% within +/-1%, same-arm spread 0.0144% | optimized 21,736,900,434 vs legacy 21,784,143,963 instructions; fingerprints match: True
ir4kFAIL0Ir -0.51% within +/-1%, same-arm spread 0.0463% | optimized 78,032,438,267 vs legacy 78,431,012,655 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 it12-parity

Write-up: 2026-10-01 - Loop iteration 12: Borrow trigger definitions during index rebuilds (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_TRIGGER_INDEX_BORROW_LEGACY, mechanism class copy. Mechanism: At game/trigger_index.rs:1136, rebuild_from_battlefield deep-clones each materialized TriggerDefinition into a SmallVec before classifying it. Add a private registration helper accepting borrowed definitions and use it during rebuilding and reindex_object_triggers. Preserve the public slice-based add API. Invariant: Classification reads definitions without modifying them. Borrowing must preserve registration order, bucket contents, duplicate suppression, synthetic-keyword routing and materialized occurrence identities. Permanently compare complete indices and ordered event candidates between both implementations, including granted/removed triggers, phased-out objects and rebuilding after deserialization.

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