MTGBench improvement loop

Overview · Experiment index

Iteration 20: Skip absent casting-permission source scans

state rejected — failed gate ir4k
switch PHASE_CAST_PERMISSION_PRESENCE_LEGACY · branch loop/it20 · base 4ec0b9ef1 · candidate a285a0ca5 · took 2h 5m

Results

Verdict: MARGINAL: 0.88% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved +0.22%, within this machine's noise (±7.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: 1,000 actions (screen) — -0.88% instructions, same-arm spread 0.033%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.88%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,758,294,41321,751,049,3794,0005,438,6682,3892,312
optimized21,561,617,60121,564,241,1344,0005,390,7322,6662,640
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.22% — cycles-neutral (same-arm spread 7.06%)same within noise
IPC (instructions per cycle, higher is better)1.010 / 1.002same
backend stall / frontend stall (share of cycles)19.5% / 19.6%  ·  41.6% / 41.0%same
L1D / L2D refills per 1k instructions (cache misses)12.91 / 12.86  ·  11.19 / 11.16same
branch mispredicts per 1k instructions5.970 / 5.782same
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: GOOD: 2.27% fewer instructions, above the 1% bar. Cycles agree (-4.13%): it should be faster in real time too. 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) — -2.27% instructions, same-arm spread 0.021%, equal work: yes, fingerprints match: yes
Gate FAILED: the harness refused this A/B (exit 2); see the write-up below. These counts are not a valid measurement.
-1% retain-0.3% kill0-2.27%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,379,782,58278,382,878,70311,4186,864,71618,28811,901
optimized76,606,261,85776,590,368,74411,4186,708,55819,03611,972
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.13% — cycles-faster (same-arm spread 1.91%)faster
IPC (instructions per cycle, higher is better)0.911 / 0.895same
backend stall / frontend stall (share of cycles)24.7% / 23.5%  ·  39.2% / 41.1%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.40 / 17.30  ·  14.07 / 13.87same
branch mispredicts per 1k instructions5.475 / 5.457same
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: 12 minexecutor: 26 minreviewer: 0 minexecutor: 66 minreviewer: 0 mingate fmt: 0 mingate build: 12 mingate ir1k: 1 mingate ir4k: 3 min
planner 12mexecutor 26mreviewer 0mexecutor 66mreviewer 0mgate fmt 0mgate build 12mgate ir1k 1mgate ir4k 3m
executor: 21,115,219 in / 39,683 out tokensplanner: 3,618,089 in / 12,647 out tokensreviewer: 45,969 in / 1,385 out tokens

Mechanism. In casting.rs, use the existing StaticModePresence summary to skip battlefield/command-zone scans for absent TopOfLibraryCastPermission, ExileCastPermission, GraveyardCastPermission, and CastFromHandFree modes. Require clean layers, a derived summary, and a valid static-source index; otherwise execute the current scan. Graveyard-resident permission sources must still be scanned because the summary does not cover them.

Evidence. xn5.67, memo L4904, and bench/reports/uprof-xn565-20260923-owners-all.txt attribute 1.6% of process CPU to spell_objects_available_to_cast; owners-alloc.txt attributes 0.9% to its allocation work. Source inspection finds permission collectors still scanning sources without the existing discriminant gate. These are family bounds; the removable permission-scan subset has no separate timer.

Counter and kill threshold. Existing xn5.67 spell_objects_available_to_cast profile row: 1.6% nearest-owner CPU. Expected reduction: 0.5–1.0% instructions per action at 4,000 actions, with uncertain coverage after the retained static-iterator change. The loop's instruction A/B decides retention.

Invariant. Absence in the clean, derived board summary proves that the corresponding board-scoped collector returns no permissions. Presence and uncertain state retain exact condition, controller, filter, frequency, and ordering checks. Preserve graveyard sources, ordered candidate vectors, auto-tap selections, and final state.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol12m 6s03,618,089 / 12,647
executorcodex / gpt-6-luna26m 50s08,321,724 / 15,592
reviewercodex / gpt-6.1-sol0m 33s022,756 / 497
executorcodex / gpt-6-luna1h 6m012,793,495 / 24,091
reviewercodex / gpt-6.1-sol0m 53s023,213 / 888

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it20-build
ir1kpass0Ir -0.88% within +/-1%, same-arm spread 0.0333% | optimized 21,562,430,308 vs legacy 21,753,639,391 instructions; fingerprints match: True
ir4kFAIL2same-arm Ir spread 0.0590% exceeds 0.05%; no verdict | optimized 76,610,729,546 vs legacy 78,381,177,510 instructions; fingerprints match: True

Write-up: 2026-10-02 - Loop iteration 20: Skip absent casting-permission source scans (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_CAST_PERMISSION_PRESENCE_LEGACY, mechanism class compute. Mechanism: In casting.rs, use the existing StaticModePresence summary to skip battlefield/command-zone scans for absent TopOfLibraryCastPermission, ExileCastPermission, GraveyardCastPermission, and CastFromHandFree modes. Require clean layers, a derived summary, and a valid static-source index; otherwise execute the current scan. Graveyard-resident permission sources must still be scanned because the summary does not cover them. Invariant: Absence in the clean, derived board summary proves that the corresponding board-scoped collector returns no permissions. Presence and uncertain state retain exact condition, controller, filter, frequency, and ordering checks. Preserve graveyard sources, ordered candidate vectors, auto-tap selections, and final state.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.88% within +/-1%, same-arm spread 0.0333%
ir4kNOsame-arm Ir spread 0.0590% exceeds 0.05%; no verdict

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