MTGBench improvement loop

Overview · Experiment index

Iteration 44: Reuse characteristic buffers during layer resets

state rejected — failed gate ir4k
switch PHASE_LAYER_RESET_BUFFERS_LEGACY · branch loop/it44 · base 4ec0b9ef1 · candidate acbdf7fd1 · took 1h 0m

Results

Verdict: TOO SMALL: only 0.06% fewer instructions, under the 0.3% floor. Cycles moved +0.67%, within this machine's noise (±5.5%): 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.06% instructions, same-arm spread 0.018%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.06%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy22,104,595,08222,105,382,7384,0005,526,2472,5482,712
optimized22,090,862,63722,094,744,0714,0005,523,2012,7422,739
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.67% — cycles-neutral (same-arm spread 5.52%)same within noise
IPC (instructions per cycle, higher is better)1.011 / 0.996same
backend stall / frontend stall (share of cycles)16.3% / 17.3%  ·  44.7% / 43.6%less waiting
L1D / L2D refills per 1k instructions (cache misses)12.69 / 12.73  ·  11.04 / 11.19same
branch mispredicts per 1k instructions5.985 / 5.930same
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.15% fewer instructions, under the 0.3% floor. Cycles moved -1.10%, within this machine's noise (±5.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: 4,000 actions (verdict) — -0.15% instructions, same-arm spread 0.021%, 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.15%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy81,058,653,46581,066,857,74211,4187,099,55818,89112,465
optimized80,947,255,84980,930,399,41311,4187,088,70420,40713,064
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.10% — cycles-neutral (same-arm spread 5.27%)same within noise
IPC (instructions per cycle, higher is better)0.889 / 0.894same
backend stall / frontend stall (share of cycles)21.2% / 20.9%  ·  43.9% / 44.0%same
L1D / L2D refills per 1k instructions (cache misses)16.79 / 16.79  ·  13.44 / 13.40same
branch mispredicts per 1k instructions5.206 / 5.264same
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: 7 minexecutor: 29 minreviewer: 0 mingate fmt: 0 mingate build: 17 mingate ir1k: 1 mingate ir4k: 3 min
planner 7mexecutor 29mreviewer 0mgate fmt 0mgate build 17mgate ir1k 1mgate ir4k 3m
executor: 6,549,424 in / 14,237 out tokensplanner: 2,289,553 in / 9,263 out tokensreviewer: 21,488 in / 836 out tokens

Mechanism. At layers.rs:2611, seed_live_characteristics_from_base replaces owned strings and vectors with newly allocated clones on every reset. Reuse destination capacity with String::clone_from and Vec::clone_from for name, card-type components, keywords and colors. For ManaCost::Cost-to-Cost resets, reuse the shards vector and assign generic; preserve clone assignment for other variant combinations. Keep every reset and subsequent layer application.

Evidence. xn5.67, docs/stage0-decision-memo.md:L4904, attributes 0.89% of sampled CPU to reset_recipient_to_base. Its allocation-owner report, bench/reports/uprof-xn565-20260923-owners-alloc.txt, also places 1.1% of allocation/copy samples under evaluate_layers; these figures overlap and must not be added. Source inspection confirms allocation-producing assignments in the reset. The profile predates later loop changes, so it supplies a historical ceiling, not current savings.

Counter and kill threshold. Existing profile row: reset_recipient_to_base, 0.89% inclusive CPU in xn5.67. Expected 4,000-action instruction reduction: 0.3–0.6% per action, an unmeasured forecast likely to enter the marginal band. Allocation savings may produce a larger wall-clock improvement. The loop's normal instruction and fingerprint gates decide.

Invariant. Reset values, vector order, keyword multiplicity, mana-cost variants and base characteristics remain identical; only destination capacity changes. Base storage and sibling forks remain independent.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol7m 39s02,289,553 / 9,263
executorcodex / gpt-6-luna29m 28s06,549,424 / 14,237
reviewercodex / gpt-6.1-sol0m 41s021,488 / 836

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it44-build
ir1kpass0Ir -0.05% within +/-1%, same-arm spread 0.0211% | optimized 22,093,706,957 vs legacy 22,104,198,730 instructions; fingerprints match: True
ir4kFAIL0Ir -0.15% within +/-1%, same-arm spread 0.0208% | optimized 80,941,217,884 vs legacy 81,066,142,787 instructions; fingerprints match: True

Write-up: 2026-10-04 - Loop iteration 44: Reuse characteristic buffers during layer resets (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_LAYER_RESET_BUFFERS_LEGACY, mechanism class allocation. Mechanism: At layers.rs:2611, seed_live_characteristics_from_base replaces owned strings and vectors with newly allocated clones on every reset. Reuse destination capacity with String::clone_from and Vec::clone_from for name, card-type components, keywords and colors. For ManaCost::Cost-to-Cost resets, reuse the shards vector and assign generic; preserve clone assignment for other variant combinations. Keep every reset and subsequent layer application. Invariant: Reset values, vector order, keyword multiplicity, mana-cost variants and base characteristics remain identical; only destination capacity changes. Base storage and sibling forks remain independent.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.05% within +/-1%, same-arm spread 0.0211%
ir4kNOIr -0.15% within +/-1%, same-arm spread 0.0208%

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