MTGBench improvement loop

Overview · Experiment index

Iteration 38: Resolve literal mana outputs without copying ability contexts

state confirm-pending — gate ir4k: marginal instruction reduction (copy); the workstation wall-clock decides
switch PHASE_LITERAL_MANA_CONTEXT_LEGACY · branch loop/it38 · base 4ec0b9ef1 · candidate 2c8e426d5 · took 2h 11m

Results

Verdict: TOO SMALL: only 0.22% fewer instructions, under the 0.3% floor. Cycles moved -2.25%, within this machine's noise (±4.3%): 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.22% instructions, same-arm spread 0.022%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.22%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,554,883,63321,555,060,2914,0005,388,7432,4882,379
optimized21,504,306,24721,509,140,6574,0005,376,6812,3742,287
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-2.25% — cycles-neutral (same-arm spread 4.32%)same within noise
IPC (instructions per cycle, higher is better)1.011 / 0.987same
backend stall / frontend stall (share of cycles)17.3% / 17.7%  ·  43.8% / 44.2%same
L1D / L2D refills per 1k instructions (cache misses)12.95 / 13.02  ·  11.26 / 11.55same
branch mispredicts per 1k instructions5.819 / 5.811same
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: MARGINAL: 0.35% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved +1.33%, within this machine's noise (±2.7%): the time effect is too small to see here; only the PC wall-clock can say. Watch: branch mispredicts +7% per instruction, so part of the saving may be paid back as slower memory or branching. The final word is always the PC wall-clock.
Gate: 4,000 actions (verdict) — -0.35% instructions, same-arm spread 0.004%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.35%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy77,476,846,16377,474,047,15911,4186,785,37818,99812,563
optimized77,199,778,35977,203,214,86911,4186,761,38519,55212,370
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.33% — cycles-neutral (same-arm spread 2.67%)same within noise
IPC (instructions per cycle, higher is better)0.890 / 0.909same
backend stall / frontend stall (share of cycles)21.0% / 21.2%  ·  44.2% / 43.6%same
L1D / L2D refills per 1k instructions (cache misses)17.48 / 17.52  ·  13.83 / 13.66same
branch mispredicts per 1k instructions5.165 / 4.834more
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.
Gate: parity (7 seeds, decks rotate per seed)
coverage: 253 distinct cards cast, 35 action kinds, 41 decision kinds, 59 event kinds, max battlefield 35, max stack 5
coverage: 143 of 257 engine counters were nonzero somewhere (unioned over 7 seeds; decks rotate per seed)
parity: 1 matched, 6 matched with an engine rejection in both arms, 0 diverged, 0 arm failures; summary /data/mtgbench/edh-play/bench/reports/it38-parity-20261003-191323-parity.json
9 games ended early on an engine rejection (counted over both arms). A rejection that happens identically in both arms is a match, but those games never reach their late game, so late-game behaviour of those decks is not exercised.

Where the time went

planner: 11 minexecutor: 40 minreviewer: 0 minexecutor: 35 minreviewer: 0 mingate fmt: 0 mingate build: 9 mingate ir1k: 1 mingate ir4k: 3 mingate check: 6 mingate focused: 16 mingate parity: 5 min
planner 11mexecutor 40mreviewer 0mexecutor 35mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3mgate check 6mgate focused 16mgate parity 5m
executor: 14,545,534 in / 32,045 out tokensplanner: 4,583,241 in / 14,271 out tokensreviewer: 44,761 in / 2,182 out tokens

Mechanism. In mana_sources.rs:emit_source_rows, literal production currently builds a complete ResolvedAbility just to determine its output. In mana_abilities.rs:produce_mana_from_ability, every recipient gets a cloned and recursively rebound ability chain. Add a shared context-free production path for Fixed, Mixed, and Colorless with QuantityExpr::Fixed. Use the existing production resolver without an ability context for these exact shapes; retain the full context path for every other shape.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, reports auto_tap_mana_sources_inner at 18.1% inclusive CPU and continue_mana_ability_cost_payment_in_node at 16.7%. Its owners-alloc report attributes 1.3% CPU to ability::impl$1662::clone. These are overlapping family ceilings, not an isolated measurement of the proposed copies. The profile predates subsequent loop changes; the removable literal-output subset remains unmeasured.

Counter and kill threshold. Existing xn5.67 mana-execution and ability-clone profile rows bound the containing work. Expected instruction reduction: 0.6–1.3% per action at 4,000 actions, a hypothesis rather than a measured result. Copy savings may land in the marginal band. Apply the loop's unchanged tiers: >=1% retained pending wall-clock; 0.3–1% marginal; <0.3%, regression, or fingerprint mismatch dropped.

Invariant. For the allowlisted production shapes, output depends only on literal descriptor fields; controller, targets, scoped player, chosen X, and cost-paid snapshots cannot affect it. Preserve mana sequence, atomic combinations, overrides, restrictions, events, replacement processing, and sub-chain execution. Permanent differential tests must compare both paths with hostile ability contexts and prove dynamic/X/cost-paid production takes the legacy context path.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol11m 18s04,583,241 / 14,271
executorcodex / gpt-6-luna40m 21s08,173,426 / 15,036
reviewercodex / gpt-6.1-sol0m 50s021,149 / 1,144
executorcodex / gpt-6-luna35m 32s06,372,108 / 17,009
reviewercodex / gpt-6.1-sol0m 50s023,612 / 1,038

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it38-build
ir1kpass0Ir -0.24% within +/-1%, same-arm spread 0.0329% | optimized 21,505,170,129 vs legacy 21,557,067,295 instructions; fingerprints match: True
ir4kFAIL0Ir -0.36% within +/-1%, same-arm spread 0.0275% | optimized 77,202,383,084 vs legacy 77,482,079,795 instructions; fingerprints match: True
checkpass0
focusedpass0
paritypass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode parity -Seeds 1,2,3,5,7,11,13 -Actions 1000 -CargoProfile bench-fast-inc -Label it38-parity

Write-up: 2026-10-03 - Loop iteration 38: Resolve literal mana outputs without copying ability contexts (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_LITERAL_MANA_CONTEXT_LEGACY, mechanism class copy. Mechanism: In mana_sources.rs:emit_source_rows, literal production currently builds a complete ResolvedAbility just to determine its output. In mana_abilities.rs:produce_mana_from_ability, every recipient gets a cloned and recursively rebound ability chain. Add a shared context-free production path for Fixed, Mixed, and Colorless with QuantityExpr::Fixed. Use the existing production resolver without an ability context for these exact shapes; retain the full context path for every other shape. Invariant: For the allowlisted production shapes, output depends only on literal descriptor fields; controller, targets, scoped player, chosen X, and cost-paid snapshots cannot affect it. Preserve mana sequence, atomic combinations, overrides, restrictions, events, replacement processing, and sub-chain execution. Permanent differential tests must compare both paths with hostile ability contexts and prove dynamic/X/cost-paid production takes the legacy context path.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.24% within +/-1%, same-arm spread 0.0329%
ir4kmarginal: workstation checkIr -0.36% within +/-1%, same-arm spread 0.0275%
checkyes
focusedyes
parityyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode parity -Seeds 1,2,3,5,7,11,1

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