MTGBench improvement loop

Overview · Experiment index

Iteration 29: Scan permanent card types once

state rejected — failed gate ir4k
switch PHASE_PERMANENT_TYPE_SCAN_LEGACY · branch loop/it29 · base 4ec0b9ef1 · candidate a81f94bdf · took 1h 5m

Results

Verdict: TOO SMALL: only 0.01% fewer instructions, under the 0.3% floor. Cycles moved -0.80%, within this machine's noise (±11.8%): 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.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.01%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,784,210,16321,783,181,0734,0005,445,9242,7592,582
optimized21,782,556,21721,782,507,3304,0005,445,6333,9313,966
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.80% — cycles-neutral (same-arm spread 11.82%)same within noise
IPC (instructions per cycle, higher is better)0.973 / 0.987same
backend stall / frontend stall (share of cycles)16.0% / 17.5%  ·  45.1% / 43.2%less waiting
L1D / L2D refills per 1k instructions (cache misses)12.93 / 12.95  ·  11.18 / 11.19same
branch mispredicts per 1k instructions5.621 / 6.069fewer
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.04% fewer instructions, under the 0.3% floor. Cycles moved +4.88%, within this machine's noise (±2.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: 4,000 actions (verdict) — -0.04% instructions, same-arm spread 0.034%, 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.04%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,428,575,53578,454,918,06511,4186,870,00819,73513,332
optimized78,420,534,28478,402,292,09511,4186,867,35120,43612,852
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.88% — cycles-neutral (same-arm spread 2.87%)same within noise
IPC (instructions per cycle, higher is better)0.862 / 0.901same
backend stall / frontend stall (share of cycles)17.6% / 22.1%  ·  48.3% / 41.8%less waiting
L1D / L2D refills per 1k instructions (cache misses)17.36 / 17.33  ·  13.83 / 13.83same
branch mispredicts per 1k instructions5.329 / 5.349same
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: 37 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 min
planner 12mexecutor 37mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3m
executor: 6,276,690 in / 15,006 out tokensplanner: 5,235,320 in / 14,487 out tokensreviewer: 23,235 in / 300 out tokens

Mechanism. In game/filter.rs, replace the six successive core_types.contains checks in TypeFilter::Permanent with one iteration using the existing CoreType::is_permanent_type authority. Apply the same mechanism to live objects, zone-change records and spell-cast records. matches_type_filter_against_face already uses this implementation.

Evidence. docs/profiles/perf-20261002-1221/w0-owners-all.txt attributes 1.6% of process CPU to type_filter_matches; other windows show 0.3–0.9%. The profile used clean Phase 4ec0b9ef1, whose deck-rotation provenance is recorded in docs/stage0-decision-memo.md:L5986. These are sampled CPU shares, not instruction savings. Permanent-specific time is unmeasured, so 1.6% is a family ceiling.

Counter and kill threshold. Existing profile row: type_filter_matches, 1.6% CPU in the seed-91/default-deck window. Expected instruction reduction: approximately 0.3–0.7% per action at 4,000 actions, conditional on Permanent's unmeasured fraction of that row. The loop decides retention using its existing tiers.

Invariant. The predicate remains true exactly when the stored type vector contains Artifact, Battle, Creature, Enchantment, Land or Planeswalker. Preserve the existing zone-independent interpretation. Add permanent differential tests over all CoreType subsets, empty and duplicate vectors, permutations, and Non/AnyOf wrappers; exercise live objects and both record readers.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol12m 15s05,235,320 / 14,487
executorcodex / gpt-6-luna37m 45s06,276,690 / 15,006
reviewercodex / gpt-6.1-sol0m 16s023,235 / 300

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it29-build
ir1kpass0Ir -0.01% within +/-1%, same-arm spread 0.0107% | optimized 21,781,762,657 vs legacy 21,783,486,642 instructions; fingerprints match: True
ir4kFAIL0Ir -0.04% within +/-1%, same-arm spread 0.0336% | optimized 78,408,150,872 vs legacy 78,441,129,792 instructions; fingerprints match: True

Write-up: 2026-10-03 - Loop iteration 29: Scan permanent card types once (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_PERMANENT_TYPE_SCAN_LEGACY, mechanism class compute. Mechanism: In game/filter.rs, replace the six successive core_types.contains checks in TypeFilter::Permanent with one iteration using the existing CoreType::is_permanent_type authority. Apply the same mechanism to live objects, zone-change records and spell-cast records. matches_type_filter_against_face already uses this implementation. Invariant: The predicate remains true exactly when the stored type vector contains Artifact, Battle, Creature, Enchantment, Land or Planeswalker. Preserve the existing zone-independent interpretation. Add permanent differential tests over all CoreType subsets, empty and duplicate vectors, permutations, and Non/AnyOf wrappers; exercise live objects and both record readers.

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.0107%
ir4kNOIr -0.04% within +/-1%, same-arm spread 0.0336%

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