Skip to content

fix(bench): build the same instruction-count binary in every checkout and host - #9574

Draft
kixelated wants to merge 7 commits into
mainfrom
quest/m0/repeatable-instruction-counts
Draft

kixelated wants to merge 7 commits into
mainfrom
quest/m0/repeatable-instruction-counts

Conversation

@kixelated

@kixelated kixelated commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The same code read different instruction counts from one run to the next, at different host loads, and in different checkouts and hosts. Noisy series feed Kixel Quest's regression filing and bisects (quest).

Findings

Diffing Callgrind profiles of runs that disagree: nearly every disagreement is the same code path hitting a different glibc malloc state (_int_malloc against a tcache hit). So any work before the measured iteration that varies will move the count. Three sources:

  • Random seeds and the host clock: fixed in rust2-bench by kixel-ai/rust2#1023 (a preloaded fixed-seed stream and deterministic clock, plus a 1 MiB padded launch). main already pins rust2 at cda8fc3e, which includes it, so this PR needs no bump.
  • Location: nix develop linked an RPATH to <checkout>/outputs/out/lib into every binary, and $CARGO_HOME registry paths land in panic locations, so the same code built a different binary per checkout and per host. This PR fixes that.

Approach

  • The dev shell sets NIX_NO_SELF_RPATH, which drops the stdenv RPATH to a directory that never exists.
  • sh/rs/instructions.sh remaps $CARGO_HOME to /cargo. It fails loud if CARGO_ENCODED_RUSTFLAGS would silently drop the remap.
  • The quest records the two-checkout idle/loaded count below and is rewritten to what remains.

Status

Not finished: the quest's proof count found 16 of 1,284 counts still move, so --jobs 1 and the wall-clock caveats stay. An attempt that dropped them (8bd0b1a5) is reverted on this branch.

Remaining (in the quest's Plan):

  1. Split the 16 movers: --jobs 1 twice in one checkout and twice in a second at a longer path, to tell load/clock from path; diff one mover's Callgrind profiles and fix the source (in swole or the bench).
  2. Recount everything idle and loaded in two checkouts; once all agree, drop --jobs 1 and the caveats in codspeed.yml, sh/rs/instructions.sh, and bench/README.md.

Impact

  • Public API: none. Wire: none.
  • Bench builds in the dev shell no longer carry the checkout RPATH. Instruction-count binaries no longer contain $CARGO_HOME paths. Counts may step once at the next nightly, since the binaries' data layout changes.

Validation

  • Earlier head: two checkouts at different paths, the second with CARGO_HOME at another path, built byte-identical jitter, varint, and both codec bench binaries (cmp), with no /home paths (strings). shellcheck, shfmt -d, nixfmt --check passed.
  • kixel-ai/rust2#1044 counted this PR's earlier head (c20f90d5) idle vs loaded from one checkout on an ubuntu-24.04 runner: all 1,284 equal.
  • This round, at 8bd0b1a5 (main merged, rust2 cda8fc3e), run 46122179148 (scratch branch, never merged, uploaded no kixel-metrics): idle start in checkout A (--jobs 1, load 0.49) against loaded checkout B at a longer path (--jobs 4 + 4 CPU burners, load 3.86 to 9.73). 1,268 of 1,284 agree; 15 moq-net stats.rs counts differ (up to 3.8%, session-report[1x10/connections=1]) plus one containers count (5,195 of 4.37G).
  • Cross-host on fedora (same fingerprint x86_64-ce1501c93c32), four named benchmarks: varint and codec full[big_static] match the runner exactly; jitter_handoff::4[64] (485,814 vs 485,750) and auth/waiting/...::128[128] (71,356,407 vs 71,364,314) do not.
  • Not run: the same-checkout vs two-checkout split (a scratch unit failed to start; stopped at the coordinator's wrap-up), just ci, /quest-review.

Alternatives

  • Fixing each bench's clock (paused tokio, or kio's simulated clock) cannot reach std's RandomState inside library code, so seeds needed rust2-bench anyway.
  • Dropping the noisy targets from the selection: the maintainer rejected this on moq-dev/moq#9555.

Decisions

  • Decided 2026-11-24 (maintainer, /quest-run): ✅ the fixed-seed and fixed-clock fix lives in rust2-bench, deterministic randomness and clock for every counted job, both in the fingerprint so Kixel Quest starts new series, binaries that bypass it refused (rejected: a paused clock in each moq bench). Decision comment.
  • The quest's completion check matches rust2's: one idle run and one loaded run, in two checkouts.
  • 2026-11-28 (iterating agent): no rust2 bump here, since main's pin already includes Rename moq binary to moq-cli #1023, and no runner change, which moq-dev/moq#9676 (move to swole) owns.

Waiting

  • Maintainer: Which of this PR and chore: count instructions with swole, rust2-bench's new repository #9676 (switch the instruction-count runner from rust2-bench to kixel-ai/swole, its new repository) lands first? They overlap only in one line of quest/m0/repeatable-instruction-counts.md; both currently conflict with or lag main.
  • Maintainer: The remaining work (16 movers) doesn't gate the 0.22.0 cut. What should happen to this PR meanwhile?
    • Land the build-side fixes now and release the claim (Recommended) - NIX_NO_SELF_RPATH and the $CARGO_HOME remap are verified (byte-identical binaries across checkouts) and independent; this PR keeps the quest open and rewritten to what remains, so a later session claims it after the cut
    • Keep it a draft holding the claim until the movers are fixed - nothing lands until then, and the branch keeps drifting from main

Follow-ups

  • None new. The remaining work stays in this PR's quest.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown
Implementer: Claude Code, claude-opus-5-5, unknown (iterate, S)
Implementer: Claude Code, claude-opus-5-5, high (iterate, M)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with high)

kixelated and others added 2 commits November 24, 2026 18:24
… and host

The dev shell no longer links an RPATH to <checkout>/outputs/out/lib, and
instructions.sh remaps CARGO_HOME, so bench binaries are byte-identical across
checkout paths and hosts. Records what still moves counts (random seeds, the
host clock, the job environment) and the rust2-bench fix it needs in the quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Every counted bench repeats its instruction count fix(bench): build the same instruction-count binary in every checkout and host Nov 25, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (/quest-run pick, 2026-11-24):

  • ✅ The fixed-seed and fixed-clock fix lives in rust2-bench: every counted job gets deterministic randomness and a deterministic clock, both enter the fingerprint so Kixel Quest starts new series, and binaries that bypass it are refused (rejected: a paused clock in each moq bench, which can't reach library HashMap seeds).

(Written by Claude Opus 5.5)

…bench-determinism

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Applied the maintainer decision in c20f90d: the quest records it, and the Maintainer wait is gone since kixel-ai/rust2's quest/m0/bench-determinism.md (kixel-ai/rust2#1016) owns the fix. This PR stays a draft on the remaining kixel-ai/rust2 wait: kixel-ai/rust2#1023 has claimed that quest but holds no work yet. Once it ships, bump rust2 here and run the two-checkout count.

(Written by Claude Opus 5.5)

Luke Curley and others added 2 commits November 27, 2026 23:37
…ny load

rust2-bench fixes each counted process's randomness and clock and pads its
launch (kixel-ai/rust2#1023), so the nightly no longer needs --jobs 1.
Finishes quest/m0/repeatable-instruction-counts.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Luke Curley and others added 2 commits November 28, 2026 02:25
…ntainers counts still move

Reverts 8bd0b1a: the proof it relied on found 16 of 1,284 counts differ, so
--jobs 1 and the caveats stay and the quest stays open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant