MTGBench improvement loop

Overview · Experiment index

Iteration 37: Narrow exact-ID layer filters before scanning recipients

state rejected — failed gate ir4k
switch PHASE_LAYER_IDENTITY_RECIPIENT_LEGACY · branch loop/it37 · base 4ec0b9ef1 · candidate 58c3e99a3 · took 1h 49m

Results

Verdict: TOO SMALL: only 0.01% fewer instructions, under the 0.3% floor. Cycles moved +0.23%, 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.01% instructions, same-arm spread 0.008%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.01%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,103,273,97722,104,275,0184,0005,525,9442,5042,406
optimized22,099,704,52422,101,446,7824,0005,525,1444,1944,503
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.23% — cycles-neutral (same-arm spread 6.89%)same within noise
IPC (instructions per cycle, higher is better)1.008 / 1.024same
backend stall / frontend stall (share of cycles)18.2% / 19.2%  ·  43.2% / 41.5%same
L1D / L2D refills per 1k instructions (cache misses)12.77 / 12.68  ·  10.93 / 11.03same
branch mispredicts per 1k instructions5.451 / 5.550same
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.12% fewer instructions, under the 0.3% floor. Cycles moved -1.64%, within this machine's noise (±3.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.12% instructions, same-arm spread 0.019%, 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.12%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,058,791,02681,074,120,79011,4187,099,88219,73313,098
optimized80,972,916,26580,973,106,52911,4187,091,69818,63212,228
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.64% — cycles-neutral (same-arm spread 3.39%)same within noise
IPC (instructions per cycle, higher is better)0.916 / 0.913same
backend stall / frontend stall (share of cycles)22.4% / 20.8%  ·  41.7% / 43.7%more waiting
L1D / L2D refills per 1k instructions (cache misses)16.74 / 16.71  ·  13.31 / 13.25same
branch mispredicts per 1k instructions4.831 / 4.784same
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: 17 minexecutor: 38 minreviewer: 2 minexecutor: 35 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 min
planner 17mexecutor 38mreviewer 2mexecutor 35mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3m
executor: 15,594,576 in / 32,676 out tokensplanner: 5,662,094 in / 17,990 out tokensreviewer: 44,464 in / 1,628 out tokens

Mechanism. In game/layers.rs:82 and apply_continuous_effect_filtered at :8960, a bare TargetFilter::SpecificObject still enumerates its zone and tests every candidate. Add a fast path that retains only the named ID when it occurs in the existing zone-cache population. Keep the existing matcher, condition checks, incremental restriction and previously retained affected set authoritative.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, attributes 2.86% inclusive CPU to apply_continuous_effect_filtered. Its owners artifact attributes 0.8% to effect_candidate_ids. These overlap and must not be summed. The profile predates the loop's recipient-buffer improvement; narrowing the number of objects tested is a distinct mechanism. Exact-ID coverage and its removable share are unmeasured.

Counter and kill threshold. Existing xn5.67 profile rows: apply_continuous_effect_filtered 2.86% inclusive and effect_candidate_ids 0.8% nearest-owner CPU. Expected instruction reduction: 0.5–1.2% per action, an estimate requiring the loop's 4,000-action gate.

Invariant. A bare SpecificObject filter cannot accept another ID. Preserve membership in the existing cached zone population; an object's zone field alone is insufficient. Permanent differential tests must compare complete derived states across battlefield, hand and stack recipients, missing IDs, phased-out recipients, duplicate ledger entries, non-materialized zones, incremental restrictions and effects already carrying retained affected sets.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol17m 31s05,662,094 / 17,990
executorcodex / gpt-6-luna38m 12s08,576,283 / 18,300
reviewercodex / gpt-6.1-sol2m 8s020,304 / 943
executorcodex / gpt-6-luna35m 50s07,018,293 / 14,376
reviewercodex / gpt-6.1-sol0m 39s024,160 / 685

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it37-build
ir1kpass0Ir -0.01% within +/-1%, same-arm spread 0.0151% | optimized 22,100,398,331 vs legacy 22,102,828,844 instructions; fingerprints match: True
ir4kFAIL0Ir -0.11% within +/-1%, same-arm spread 0.0202% | optimized 80,973,967,869 vs legacy 81,063,554,464 instructions; fingerprints match: True

Write-up: 2026-10-03 - Loop iteration 37: Narrow exact-ID layer filters before scanning recipients (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_LAYER_IDENTITY_RECIPIENT_LEGACY, mechanism class compute. Mechanism: In game/layers.rs:82 and apply_continuous_effect_filtered at :8960, a bare TargetFilter::SpecificObject still enumerates its zone and tests every candidate. Add a fast path that retains only the named ID when it occurs in the existing zone-cache population. Keep the existing matcher, condition checks, incremental restriction and previously retained affected set authoritative. Invariant: A bare SpecificObject filter cannot accept another ID. Preserve membership in the existing cached zone population; an object's zone field alone is insufficient. Permanent differential tests must compare complete derived states across battlefield, hand and stack recipients, missing IDs, phased-out recipients, duplicate ledger entries, non-materialized zones, incremental restrictions and effects already carrying retained affected sets.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.01% within +/-1%, same-arm spread 0.0151%
ir4kNOIr -0.11% within +/-1%, same-arm spread 0.0202%

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