MTGBench improvement loop

Overview · Experiment index

Iteration 46: Remove boxing from active trigger iteration

state rejected — failed gate ir4k
switch PHASE_TRIGGER_ITERATOR_BOX_LEGACY · branch loop/it46 · base 4ec0b9ef1 · candidate 1adfda210 · took 1h 17m

Results

Verdict: TOO SMALL: only 0.04% fewer instructions, under the 0.3% floor. Cycles moved -4.44%, within this machine's noise (±4.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.04% instructions, same-arm spread 0.015%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.04%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,787,875,13921,789,451,6194,0005,447,1663,0142,670
optimized21,778,195,22421,781,550,5014,0005,444,9682,6892,562
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-4.44% — cycles-neutral (same-arm spread 4.89%)same within noise
IPC (instructions per cycle, higher is better)1.008 / 0.969same
backend stall / frontend stall (share of cycles)16.1% / 15.5%  ·  44.6% / 46.7%same
L1D / L2D refills per 1k instructions (cache misses)12.86 / 12.83  ·  11.13 / 11.50same
branch mispredicts per 1k instructions5.759 / 5.830same
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: TOO SMALL: only 0.15% fewer instructions, under the 0.3% floor. Cycles moved -0.92%, within this machine's noise (±3.3%): 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.15% instructions, same-arm spread 0.032%, 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.15%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,513,936,72878,505,707,51611,4186,875,97019,37613,234
optimized78,383,413,49578,408,337,08911,4186,865,99018,94812,394
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.92% — cycles-neutral (same-arm spread 3.26%)same within noise
IPC (instructions per cycle, higher is better)0.893 / 0.895same
backend stall / frontend stall (share of cycles)21.5% / 19.9%  ·  43.4% / 45.1%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.30 / 17.31  ·  13.86 / 13.70same
branch mispredicts per 1k instructions5.178 / 5.084same
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: 6 minexecutor: 52 minreviewer: 0 mingate fmt: 0 mingate build: 11 mingate ir1k: 1 mingate ir4k: 3 min
planner 6mexecutor 52mreviewer 0mgate fmt 0mgate build 11mgate ir1k 1mgate ir4k 3m
executor: 6,558,094 in / 16,246 out tokensplanner: 2,399,155 in / 8,941 out tokensreviewer: 24,206 in / 459 out tokens

Mechanism. At functioning_abilities.rs:440–483, active_trigger_definitions allocates a boxed iterator for each functioning source. Return a concrete borrowed iterator, carrying the original boxed implementation as its legacy variant. Preserve definition gating and occurrence construction.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, measures collect_matching_triggers_inner at 1.6% inclusive CPU. Its linked bench/reports/uprof-xn565-20260923-owners-alloc.txt attributes approximately 0.2% CPU each to allocation/copy work owned by collect_matching_triggers_inner and check_state_triggers. These are containing bounds, not isolated boxing costs. The profile predates subsequent retained changes. This targets triggers separately from the previously tried static iterator optimization; loop history contains only unchosen proposals for this mechanism.

Counter and kill threshold. Existing xn5.67 collect_matching_triggers_inner inclusive row and trigger allocation-owner rows bound the opportunity. Expected instruction reduction: 0.3–0.6% per action at 4,000 actions, an uncertain planning hypothesis. Expect the marginal band because instruction counts under-report allocation savings.

Invariant. Both paths yield identical ordered live_index, occurrence-bearing definition_ref and borrowed definition values. Preserve eliminated-owner, phasing, Room-door and command-zone gates; enumerate before filtering. Intervening-if evaluation remains at existing callers. Permanent differential tests must compare complete identities and partial-consumption behavior, including duplicate payloads with distinct occurrences.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol6m 42s02,399,155 / 8,941
executorcodex / gpt-6-luna52m 33s06,558,094 / 16,246
reviewercodex / gpt-6.1-sol0m 27s024,206 / 459

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it46-build
ir1kpass0Ir -0.04% within +/-1%, same-arm spread 0.0163% | optimized 21,780,500,418 vs legacy 21,789,018,113 instructions; fingerprints match: True
ir4kFAIL0Ir -0.14% within +/-1%, same-arm spread 0.0320% | optimized 78,400,083,039 vs legacy 78,510,843,855 instructions; fingerprints match: True

Write-up: 2026-10-04 - Loop iteration 46: Remove boxing from active trigger iteration (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_TRIGGER_ITERATOR_BOX_LEGACY, mechanism class allocation. Mechanism: At functioning_abilities.rs:440–483, active_trigger_definitions allocates a boxed iterator for each functioning source. Return a concrete borrowed iterator, carrying the original boxed implementation as its legacy variant. Preserve definition gating and occurrence construction. Invariant: Both paths yield identical ordered live_index, occurrence-bearing definition_ref and borrowed definition values. Preserve eliminated-owner, phasing, Room-door and command-zone gates; enumerate before filtering. Intervening-if evaluation remains at existing callers. Permanent differential tests must compare complete identities and partial-consumption behavior, including duplicate payloads with distinct occurrences.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.04% within +/-1%, same-arm spread 0.0163%
ir4kNOIr -0.14% within +/-1%, same-arm spread 0.0320%

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