MTGBench improvement loop

Overview · Experiment index

Iteration 43: Avoid temporary vectors in mana color-capability queries

state rejected — failed gate ir4k
switch PHASE_MANA_COLOR_CAPABILITY_LEGACY · branch loop/it43 · base 4ec0b9ef1 · candidate 2e3d19326 · took 1h 8m

Results

Verdict: TOO SMALL: only 0.02% fewer instructions, under the 0.3% floor. Cycles moved -3.43%, within this machine's noise (±5.7%): 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.02% instructions, same-arm spread 0.008%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.02%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,564,879,44021,563,260,2594,0005,391,0172,7692,595
optimized21,560,139,84021,558,670,0944,0005,389,8512,6392,518
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-3.43% — cycles-neutral (same-arm spread 5.73%)same within noise
IPC (instructions per cycle, higher is better)1.026 / 0.992same
backend stall / frontend stall (share of cycles)19.3% / 17.8%  ·  40.9% / 43.9%more waiting
L1D / L2D refills per 1k instructions (cache misses)13.03 / 13.04  ·  11.34 / 11.44same
branch mispredicts per 1k instructions5.850 / 5.935same
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 -0.39%, within this machine's noise (±3.0%): 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.004%, 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
legacy77,558,347,74977,555,297,89511,4186,792,50519,39513,430
optimized77,521,976,94677,523,716,53911,4186,789,52917,60311,561
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.39% — cycles-neutral (same-arm spread 2.97%)same within noise
IPC (instructions per cycle, higher is better)0.886 / 0.883same
backend stall / frontend stall (share of cycles)18.7% / 18.3%  ·  46.8% / 47.4%same
L1D / L2D refills per 1k instructions (cache misses)17.49 / 17.52  ·  14.01 / 13.95same
branch mispredicts per 1k instructions5.259 / 5.206same
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: 10 minexecutor: 33 minreviewer: 0 mingate fmt: 0 mingate build: 19 mingate ir1k: 1 mingate ir4k: 3 min
planner 10mexecutor 33mreviewer 0mgate fmt 0mgate build 19mgate ir1k 1mgate ir4k 3m
executor: 4,109,527 in / 14,335 out tokensplanner: 2,304,640 in / 12,485 out tokensreviewer: 97,021 in / 734 out tokens

Mechanism. At mana_sources.rs:3128–3190, source_could_produce_two_or_more_colors and mana_production_could_produce_two_or_more_colors allocate vectors to answer a Boolean question. Use a stack-resident, saturating two-distinct-color accumulator. Feed literal production variants directly from their existing color slices; retain mana_options_from_production for dynamic variants.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, profiles auto_tap_mana_sources_inner at 18.1% inclusive. Its saved workload report, bench/reports/uprof-xn565-20260923-workload.json, records source discovery at 122/7155 ms, or 1.70% of contract+apply. The saved owners report attributes another 1.5% of process CPU to produce_mana_with_attributes_from_source_quality, which also performs the capability query. These are separate parent bounds, not additive savings; the capability query itself is not isolated.

Counter and kill threshold. Existing auto_tap_source_discovery_ms and xn5.67 mana-production owner row bound the affected regions. Expected instruction reduction: 0.3–0.8% per action, with substantial uncertainty about the removable fraction. Allocation savings may be under-reported; expect a marginal result requiring workstation wall-clock confirmation.

Invariant. Return exactly whether the existing capability calculation finds at least two distinct non-colorless colors. Preserve its treatment of production counts, duplicate colors, basic-land subtypes and dynamic production; do not substitute current activation legality for capability. Permanent differential tests compare both helpers against the legacy implementation.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol10m 4s02,304,640 / 12,485
executorcodex / gpt-6-luna33m 22s04,109,527 / 14,335
reviewercodex / gpt-6.1-sol0m 46s097,021 / 734

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it43-build
ir1kpass0Ir -0.03% within +/-1%, same-arm spread 0.0152% | optimized 21,558,558,915 vs legacy 21,564,292,488 instructions; fingerprints match: True
ir4kFAIL0Ir -0.04% within +/-1%, same-arm spread 0.0101% | optimized 77,520,526,276 vs legacy 77,554,897,169 instructions; fingerprints match: True

Write-up: 2026-10-04 - Loop iteration 43: Avoid temporary vectors in mana color-capability queries (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_MANA_COLOR_CAPABILITY_LEGACY, mechanism class allocation. Mechanism: At mana_sources.rs:3128–3190, source_could_produce_two_or_more_colors and mana_production_could_produce_two_or_more_colors allocate vectors to answer a Boolean question. Use a stack-resident, saturating two-distinct-color accumulator. Feed literal production variants directly from their existing color slices; retain mana_options_from_production for dynamic variants. Invariant: Return exactly whether the existing capability calculation finds at least two distinct non-colorless colors. Preserve its treatment of production counts, duplicate colors, basic-land subtypes and dynamic production; do not substitute current activation legality for capability. Permanent differential tests compare both helpers against the legacy implementation.

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

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