MTGBench improvement loop

Overview · Experiment index

Iteration 39: Defer mutable access in optional layer fixups

state rejected — failed gate ir4k
switch PHASE_OPTIONAL_LAYER_WRITES_LEGACY · branch loop/it39 · base 4ec0b9ef1 · candidate 0888d9790 · took 59m 44s

Results

Verdict: TOO SMALL: only 0.03% fewer instructions, under the 0.3% floor. Cycles moved +1.22%, within this machine's noise (±5.2%): 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.03% instructions, same-arm spread 0.008%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.03%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,090,901,07722,092,234,0244,0005,522,8922,8172,589
optimized22,086,490,47422,084,613,8624,0005,521,3882,8142,845
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.22% — cycles-neutral (same-arm spread 5.17%)same within noise
IPC (instructions per cycle, higher is better)1.009 / 0.996same
backend stall / frontend stall (share of cycles)17.3% / 17.7%  ·  43.4% / 43.3%same
L1D / L2D refills per 1k instructions (cache misses)12.63 / 12.65  ·  11.11 / 11.15same
branch mispredicts per 1k instructions5.830 / 6.299fewer
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 -2.11%, 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.026%, 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,028,995,36481,008,173,62711,4187,095,69018,24211,852
optimized80,949,583,77080,956,161,23911,4187,089,93519,00112,091
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.11% — cycles-neutral (same-arm spread 4.07%)same within noise
IPC (instructions per cycle, higher is better)0.925 / 0.910same
backend stall / frontend stall (share of cycles)21.0% / 20.8%  ·  42.8% / 43.4%same
L1D / L2D refills per 1k instructions (cache misses)16.74 / 16.70  ·  13.47 / 13.50same
branch mispredicts per 1k instructions5.315 / 5.369same
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: 9 mingate ir1k: 1 mingate ir4k: 3 min
planner 10mexecutor 33mreviewer 0mgate fmt 0mgate build 9mgate ir1k 1mgate ir4k 3m
executor: 5,282,952 in / 15,965 out tokensplanner: 3,460,544 in / 13,782 out tokensreviewer: 23,369 in / 873 out tokens

Mechanism. In layers.rs, derive_room_battlefield_names, apply_prototype_characteristics and apply_pt_counter_modifications acquire ObjectStore::get_mut before determining whether they have work. Inspect the object immutably, compute the existing name, prototype payload or counter deltas, and acquire mutable access only when the existing code would write.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, attributes 2.20% inclusive process CPU to ObjectStore::get_mut beneath evaluate_layers. This bounds the containing mutable-access work; the three fixups have no isolated timer. xn5.46 at L3311 rejected a more expensive whole-characteristics reset predicate. The profile predates subsequent loop changes, so its share is historical attribution.

Counter and kill threshold. Existing xn5.67 evaluate_layers -> ObjectStore::get_mut profile row: 2.20% inclusive CPU. Expected instruction reduction: 0.5–1.0% per action at 4,000 actions, an unmeasured hypothesis. Most full-pass objects have already been detached by reset; the expected benefit is fewer mutable lookups and Arc::make_mut checks, not guaranteed clone elimination.

Invariant. These helpers mutate only their supplied object's fields and do not change population membership. Immutable preparation must retain every existing guard, write, arithmetic operation and checkpoint. Add permanent differential tests covering ordinary objects, prototype payloads, locked/unlocked and copied Rooms, face-down objects, copy-name exceptions, sticker ordering, zero counters, non-P/T counters, cancelling P/T deltas and saturating arithmetic. Include positive fixtures proving each write branch executes.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol10m 26s03,460,544 / 13,782
executorcodex / gpt-6-luna33m 52s05,282,952 / 15,965
reviewercodex / gpt-6.1-sol0m 39s023,369 / 873

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it39-build
ir1kpass0Ir -0.03% within +/-1%, same-arm spread 0.0159% | optimized 22,085,076,732 vs legacy 22,090,621,970 instructions; fingerprints match: True
ir4kFAIL0Ir -0.08% within +/-1%, same-arm spread 0.0257% | optimized 80,953,000,521 vs legacy 81,018,386,509 instructions; fingerprints match: True

Write-up: 2026-10-03 - Loop iteration 39: Defer mutable access in optional layer fixups (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_OPTIONAL_LAYER_WRITES_LEGACY, mechanism class compute. Mechanism: In layers.rs, derive_room_battlefield_names, apply_prototype_characteristics and apply_pt_counter_modifications acquire ObjectStore::get_mut before determining whether they have work. Inspect the object immutably, compute the existing name, prototype payload or counter deltas, and acquire mutable access only when the existing code would write. Invariant: These helpers mutate only their supplied object's fields and do not change population membership. Immutable preparation must retain every existing guard, write, arithmetic operation and checkpoint. Add permanent differential tests covering ordinary objects, prototype payloads, locked/unlocked and copied Rooms, face-down objects, copy-name exceptions, sticker ordering, zero counters, non-P/T counters, cancelling P/T deltas and saturating arithmetic. Include positive fixtures proving each write branch executes.

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

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