MTGBench improvement loop

Overview · Experiment index

Iteration 26: Borrow auxiliary data in filter source contexts

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

Results

Verdict: TOO SMALL: only 0.07% fewer instructions, under the 0.3% floor. Cycles moved -0.80%, within this machine's noise (±6.9%): 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.07% instructions, same-arm spread 0.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.07%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,783,309,46121,784,300,8724,0005,445,9512,9512,974
optimized21,769,529,49721,769,013,6794,0005,442,3182,9842,849
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.80% — cycles-neutral (same-arm spread 6.87%)same within noise
IPC (instructions per cycle, higher is better)1.025 / 0.990same
backend stall / frontend stall (share of cycles)17.5% / 17.2%  ·  42.9% / 43.2%same
L1D / L2D refills per 1k instructions (cache misses)12.88 / 12.93  ·  11.03 / 11.20same
branch mispredicts per 1k instructions5.762 / 6.074fewer
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.75% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. Cycles moved -1.22%, within this machine's noise (±4.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.75% instructions, same-arm spread 0.027%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.75%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,414,887,53978,425,580,11411,4186,868,12319,40813,524
optimized77,825,399,11677,846,308,52611,4186,816,94317,51411,382
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 3.96%)same within noise
IPC (instructions per cycle, higher is better)0.914 / 0.898same
backend stall / frontend stall (share of cycles)20.3% / 18.1%  ·  43.8% / 47.2%more waiting
L1D / L2D refills per 1k instructions (cache misses)17.39 / 17.24  ·  13.64 / 13.55same
branch mispredicts per 1k instructions4.944 / 4.977same
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/it26-parity-20261002-193003-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: 8 minexecutor: 68 minreviewer: 0 mingate fmt: 0 mingate build: 8 mingate ir1k: 1 mingate ir4k: 3 mingate check: 20 mingate focused: 45 mingate parity: 5 min
planner 8mexecutor 68mreviewer 0mgate fmt 0mgate build 8mgate ir1k 1mgate ir4k 3mgate check 20mgate focused 45mgate parity 5m
executor: 10,288,588 in / 20,633 out tokensplanner: 3,343,192 in / 11,123 out tokensreviewer: 25,175 in / 1,336 out tokens

Mechanism. In game/filter.rs, source_context_from_filter_with_family clones saddled_by, convoked_creatures, linked_exile_snapshot, chosen_attributes, and the chosen creature-type string into an ephemeral, read-only SourceContext. Represent these payloads with borrowed-or-owned views: borrow in the optimized arm and preserve the current copies in the legacy arm.

Evidence. xn5.67, memo L4904, references bench/reports/uprof-xn565-20260923-owners-all.txt, where source_context_from_filter_with_family owns 1.1% of process CPU. xn5.50, memo L3603, established the existing borrowed source authority and lazy LKI mechanism. The auxiliary-copy fraction is unmeasured; 1.1% bounds the containing function, not the savings. The profile predates later loop changes.

Counter and kill threshold. Existing source_contexts_built/source_contexts_lki_materialized counters and xn5.67's 1.1% source-context owner row. Expected instruction reduction: approximately 0.3–0.7% per action at 4,000 actions, with substantial uncertainty about nonempty payload frequency. Copy and allocation savings may be under-reported by instructions.

Invariant. Borrow precisely the payload the old path copied, preserving the distinction between exact-live source facts and latched trigger choices. SourceContext remains confined to an immutable evaluation and never escapes. Keep the existing LKI materialization and incarnation checks unchanged. A permanent owned-versus-borrowed differential regression must cover live, latched, cached-LKI, missing-source, and recycled-id cases with nonempty auxiliary payloads.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol8m 53s03,343,192 / 11,123
executorcodex / gpt-6-luna1h 8m010,288,588 / 20,633
reviewercodex / gpt-6.1-sol0m 55s025,175 / 1,336

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it26-build
ir1kpass0Ir -0.06% within +/-1%, same-arm spread 0.0114% | optimized 21,769,612,674 vs legacy 21,783,145,029 instructions; fingerprints match: True
ir4kFAIL0Ir -0.74% within +/-1%, same-arm spread 0.0269% | optimized 77,834,662,036 vs legacy 78,415,739,527 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 it26-parity

Write-up: 2026-10-02 - Loop iteration 26: Borrow auxiliary data in filter source contexts (confirm-pending)

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

Automated loop result on homelab (aarch64). Switch PHASE_FILTER_SOURCE_PAYLOAD_LEGACY, mechanism class copy. Mechanism: In game/filter.rs, source_context_from_filter_with_family clones saddled_by, convoked_creatures, linked_exile_snapshot, chosen_attributes, and the chosen creature-type string into an ephemeral, read-only SourceContext. Represent these payloads with borrowed-or-owned views: borrow in the optimized arm and preserve the current copies in the legacy arm. Invariant: Borrow precisely the payload the old path copied, preserving the distinction between exact-live source facts and latched trigger choices. SourceContext remains confined to an immutable evaluation and never escapes. Keep the existing LKI materialization and incarnation checks unchanged. A permanent owned-versus-borrowed differential regression must cover live, latched, cached-LKI, missing-source, and recycled-id cases with nonempty auxiliary payloads.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.06% within +/-1%, same-arm spread 0.0114%
ir4kmarginal: workstation checkIr -0.74% within +/-1%, same-arm spread 0.0269%
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:17 · read-only · refreshes every 30 s