MTGBench improvement loop

Overview · Experiment index

Iteration 23: Compute auto-tap source sort keys once per option

state rejected — failed gate ir4k
switch PHASE_MANA_SOURCE_SORT_KEYS_LEGACY · branch loop/it23 · base 4ec0b9ef1 · candidate 4379c958a · took 1h 3m

Results

Verdict: TOO SMALL: only 0.01% fewer instructions, under the 0.3% floor. Cycles moved -1.81%, within this machine's noise (±6.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.007%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.01%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,096,806,85622,096,208,9514,0005,524,1272,4542,294
optimized22,092,503,04122,093,975,0034,0005,523,3103,5703,486
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.81% — cycles-neutral (same-arm spread 6.77%)same within noise
IPC (instructions per cycle, higher is better)1.007 / 0.997same
backend stall / frontend stall (share of cycles)22.2% / 20.0%  ·  39.0% / 41.7%more waiting
L1D / L2D refills per 1k instructions (cache misses)12.76 / 12.69  ·  11.17 / 11.32same
branch mispredicts per 1k instructions5.904 / 5.928same
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.08% fewer instructions, under the 0.3% floor. Cycles moved -0.63%, within this machine's noise (±4.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.08% instructions, same-arm spread 0.009%, 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.08%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,053,635,62881,046,657,71711,4187,098,45419,85213,045
optimized80,987,625,21080,988,460,13811,4187,093,01518,98312,730
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.63% — cycles-neutral (same-arm spread 4.13%)same within noise
IPC (instructions per cycle, higher is better)0.893 / 0.901same
backend stall / frontend stall (share of cycles)23.3% / 22.5%  ·  41.9% / 42.5%same
L1D / L2D refills per 1k instructions (cache misses)16.78 / 16.76  ·  13.48 / 13.55same
branch mispredicts per 1k instructions5.283 / 5.363same
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: 8 minexecutor: 31 minreviewer: 0 mingate fmt: 0 mingate build: 17 mingate ir1k: 1 mingate ir4k: 3 min
planner 8mexecutor 31mreviewer 0mgate fmt 0mgate build 17mgate ir1k 1mgate ir4k 3m
executor: 7,540,633 in / 14,530 out tokensplanner: 3,039,451 in / 10,486 out tokensreviewer: 22,474 in / 543 out tokens

Mechanism. In casting_costs.rs::collect_sorted_auto_tap_source_options, sort_by_key repeatedly evaluates a key that looks up the source in ObjectStore and inspects its card types and supertypes. Use stable sort_by_cached_key in the optimized arm so each option's unchanged key is computed once.

Evidence. The existing auto_tap_source_discovery_ms counter measured 512 ms out of 30,469 ms contract+apply (1.68%) across 11,418 actions in bench/reports/it19-ir4k-20261002-032339-legacy.json. That pair passed equal-work and fingerprint checks. This bounds the containing discovery region; sorting has no separate timer. The xn5.67 profile at docs/stage0-decision-memo.md:L4904 independently identifies auto-tap as an 18.1% inclusive family, which must not be added to the discovery timer.

Counter and kill threshold. auto_tap_source_discovery_ms: 1.68% diagnostic containing-region share. Expected instruction reduction: 0.3–0.7% per action, an unmeasured hypothesis; key computation's fraction is unknown. Expect marginal if successful, with the loop's 4,000-action gate deciding.

Invariant. Source collection and the lexicographic key remain identical. State is immutable throughout sorting, and equal keys retain original option order. Therefore the entire ordered option vector, selected sources, action stream and final state must match.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 49s03,039,451 / 10,486
executorcodex / gpt-6-luna31m 34s07,540,633 / 14,530
reviewercodex / gpt-6.1-sol0m 34s022,474 / 543

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it23-build
ir1kpass0Ir -0.01% within +/-1%, same-arm spread 0.0095% | optimized 22,092,895,812 vs legacy 22,095,904,484 instructions; fingerprints match: True
ir4kFAIL0Ir -0.08% within +/-1%, same-arm spread 0.0356% | optimized 80,992,850,042 vs legacy 81,058,603,116 instructions; fingerprints match: True

Write-up: 2026-10-02 - Loop iteration 23: Compute auto-tap source sort keys once per option (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_MANA_SOURCE_SORT_KEYS_LEGACY, mechanism class compute. Mechanism: In casting_costs.rs::collect_sorted_auto_tap_source_options, sort_by_key repeatedly evaluates a key that looks up the source in ObjectStore and inspects its card types and supertypes. Use stable sort_by_cached_key in the optimized arm so each option's unchanged key is computed once. Invariant: Source collection and the lexicographic key remain identical. State is immutable throughout sorting, and equal keys retain original option order. Therefore the entire ordered option vector, selected sources, action stream and final state must match.

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.0095%
ir4kNOIr -0.08% within +/-1%, same-arm spread 0.0356%

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