MTGBench improvement loop

Overview · Experiment index

Iteration 10: Replace replacement-event buckets with one ordered flat vector

state rejected — failed gate focused
switch PHASE_REPLACEMENT_FLAT_INDEX_LEGACY · branch loop/it10 · base 4ec0b9ef1 · candidate dc34b10bd · took 4h 12m

Results

Verdict: MARGINAL: 0.97% fewer instructions, between 0.3% and 1%. It is sent to the PC wall-clock check instead of being kept outright. The final word is always the PC wall-clock.
Gate: 1,000 actions (screen) — -0.97% instructions, same-arm spread 0.005%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-0.97%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy21,778,210,90321,778,597,2964,0005,444,6012,5592,298
optimized21,568,575,07221,567,553,3664,0005,392,0162,3692,397
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.
Verdict: GOOD: 1.10% fewer instructions, above the 1% bar. The final word is always the PC wall-clock.
Gate: 4,000 actions (verdict) — -1.10% instructions, same-arm spread 0.006%, equal work: yes, fingerprints match: yes-1% retain-0.3% kill0-1.10%
ArmRun 1 instructionsRun 2ActionsInstr / actioncontract msapply ms
legacy78,429,261,37378,427,972,45911,4186,868,85819,08212,508
optimized77,569,327,84777,564,823,87311,4186,793,40318,69911,958
Instruction counts are deterministic and machine-specific (aarch64 homelab). contract and apply ms are wall time under perf: indicative only, not a clean timing.

Where the time went

planner: 10 minexecutor: 80 minreviewer: 0 minexecutor: 37 minreviewer: 1 mingate fmt: 0 mingate build: 25 mingate ir1k: 0 mingate ir4k: 2 mingate check: 31 mingate focused: 60 min
planner 10mexecutor 80mreviewer 0mexecutor 37mreviewer 1mgate fmt 0mgate build 25mgate ir1k 0mgate ir4k 2mgate check 31mgate focused 60m
executor: 19,250,429 in / 40,810 out tokensplanner: 2,132,991 in / 10,968 out tokensreviewer: 50,486 in / 2,221 out tokens

Mechanism. At replacement.rs:7233, rebuild a contiguous Vec<(ReplacementEvent, ReplacementIndexEntry)> in active-replacement scan order. At indexed_object_replacement_candidates_from_index, select entries whose event matches any requested key and retain the existing live applicability checks. This removes persistent HAMT/vector bucket construction and naturally produces ordinal order without sorting.

Evidence. xn5.69, docs/stage0-decision-memo.md:L5379, measured bucket assembly at 1.141%/1.207% of contract+apply and assembly+drop+index-clone at 1.302%/1.370% for seeds 91/42. Reports: bench/reports/xn569-counter-s91-20260924-131701-* and xn569-counter-s42-20260924-132036-*. These bound representation work, not scan work. The measurements predate subsequent retained changes.

Counter and kill threshold. Existing replacement_index_bucket_assembly_ns, replacement_index_bucket_drop_ns and replacement_index_clone_ns bound the opportunity. Expected instruction reduction: 0.4–0.8% per action at 4,000 actions, a hypothesis in the marginal band. Allocation savings can exceed their instruction-count effect; linear lookup overhead could erase them. Apply the loop's existing tiers.

Invariant. The ordered replacement candidates, virtual-candidate prefix, liminal-entry suffix and dynamic applicability predicates remain identical. Rebuild at every pipeline entry and preserve invalidation after replacement application; ReplacementIndex::clone must still return an uninitialized index. Add a permanent differential regression covering multiple event keys, candidate ordering, floating/virtual replacements, liminal entries, same-revision definition mutation and fork isolation.

Agent steps

RoleHarness / modelTimeExitTokens in / outNote
plannercodex / gpt-6.1-sol10m 56s02,132,991 / 10,968
executorcodex / gpt-6-luna1h 20m011,904,897 / 23,119
reviewercodex / gpt-6.1-sol0m 59s024,337 / 1,107
executorcodex / gpt-6-luna37m 42s07,345,532 / 17,691
reviewercodex / gpt-6.1-sol1m 5s026,149 / 1,114

Gates

GateResultExitDetail
fmtpass0cargo fmt --all -- --check
buildpass0pwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fast-inc -Label it10-build
ir1kpass0Ir -0.97% within +/-1%, same-arm spread 0.0047% | optimized 21,568,064,219 vs legacy 21,778,404,100 instructions; fingerprints match: True
ir4kpass0Ir -1.10% (threshold -1%), same-arm spread 0.0058% | optimized 77,567,075,860 vs legacy 78,428,616,916 instructions; fingerprints match: True
checkpass0
focusedFAIL101

Write-up: 2026-10-01 - Loop iteration 10: Replace replacement-event buckets with one ordered flat vector (rejected)

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

Automated loop result on homelab (aarch64). Switch PHASE_REPLACEMENT_FLAT_INDEX_LEGACY, mechanism class allocation. Mechanism: At replacement.rs:7233, rebuild a contiguous Vec<(ReplacementEvent, ReplacementIndexEntry)> in active-replacement scan order. At indexed_object_replacement_candidates_from_index, select entries whose event matches any requested key and retain the existing live applicability checks. This removes persistent HAMT/vector bucket construction and naturally produces ordinal order without sorting. Invariant: The ordered replacement candidates, virtual-candidate prefix, liminal-entry suffix and dynamic applicability predicates remain identical. Rebuild at every pipeline entry and preserve invalidation after replacement application; ReplacementIndex::clone must still return an uninitialized index. Add a permanent differential regression covering multiple event keys, candidate ordering, floating/virtual replacements, liminal entries, same-revision definition mutation and fork isolation.

gatepasseddetail
fmtyescargo fmt --all -- --check
buildyespwsh -NoProfile -File scripts/bench_phase.ps1 -Mode build -CargoProfile bench-fa
ir1kyesIr -0.97% within +/-1%, same-arm spread 0.0047%
ir4kyesIr -1.10% (threshold -1%), same-arm spread 0.0058%
checkyes
focusedNO

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