perf(ci): budgets pinned per platform inside the CI image; jobs install mold and valgrind; runner keeps ASLR
bb32860e4b5613126e7bbd493b35dc7402996c76
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 5f9e275d2cd4
There are many coding harnesses - but this one is fast
bb32860e4b5613126e7bbd493b35dc7402996c76
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+100 / −31 text lines
+1 / −0 text lines
+1 / −0 text lines
+1 / −0 text lines
run "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq mold valgrind"+1 / −1 text lines
+1 / −0 text lines
run "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq mold valgrind"+1 / −1 text lines
- golden corpus: checked-in sessions; replay and trace byte-identical; regenerated only with a frame-version bump. - instruction budgets: callgrind instruction counts per hot path (`gungraun`), pinned in `smith-bench/budgets.toml` with a ±2 % band; a regression fails, an improvement fails until re-pinned; re-pins are deliberate commits, toolchain bumps the expected trigger. - instruction budgets: callgrind instruction counts per hot path (`gungraun`), pinned in `smith-bench/budgets.toml` with a ±2 % band for the platform (toolchain and libc) named in the pins, the CI image; other platforms report without gating; a regression fails, an improvement fails until re-pinned; re-pins are deliberate commits, toolchain bumps the expected trigger.+1 / −1 text lines
- Three signals, each where it is strong: allocation counts (exact, tests), instruction counts (`gungraun` over callgrind, exact per toolchain, CI gate), wall clock (`criterion`, `hyperfine`, local A/B, never committed).- Budgets are pinned per bench in `smith-bench/budgets.toml`; the gate is a ±2 % band on `Ir`; both directions fail so pins stay honest; re-pin is a deliberate commit.- Budgets are pinned per bench in `smith-bench/budgets.toml` for one platform (toolchain and libc, the CI image); the gate is a ±2 % band on `Ir` on that platform and a report elsewhere (glibc 2.41 versus 2.44 moved counts by 3 to 23 %); both directions fail so pins stay honest; re-pin is a deliberate commit made inside the CI image (`docker run … rust:latest … cargo x perf --pin`).+8 / −0 text lines
- [gungraun guide](https://gungraun.github.io/gungraun/latest/html/): default environment clearing, entry points, binary benchmarks, command-line arguments, machine-readable output.- `gungraun-runner` 0.19.4 source, `src/runner/args.rs`: environment clearing preserves `LD_PRELOAD` and `LD_LIBRARY_PATH`.## Platform dependence, measuredThe same tree on the same rustc under Debian glibc 2.41 (the `rust:latest` image) versus CachyOS glibc 2.44: SSE decoders +9 to +11 %, `handle_line::ping` +23 %, `smith --help` −4.6 %, `eval --mock` +3.6 %, frame encode +3.3 %; the rest within 1.5 %.Startup counts include the dynamic loader; every bench includes libc `malloc` and `memcpy`, whose implementations differ per glibc release.Consequence: pins carry the platform (`# Pinned with <rustc> | glibc <v>`); the gate applies only on that platform, other hosts only report; pins are taken inside the CI image.Inside the container `setarch` cannot disable ASLR, so the runner always gets `--allow-aslr=true`; with cache simulation off the counts stayed within band across repeated container runs.The CI image also lacks `mold`, which `.cargo/config.toml` requires; every job installs `mold` (and `valgrind` where callgrind runs) first.+15 / −15 text lines
# Pinned with rustc 1.98.1 (48a229cea 2026-09-01).# Pinned with rustc 1.98.1 (48a229cea 2026-09-01) | glibc 2.41."instructions::agent::run_turn::history_1000_masked" = { ir = 11270600 }"instructions::providers::sse::anthropic" = { ir = 109026 }"instructions::providers::sse::gemini" = { ir = 47234 }"instructions::providers::sse::openai" = { ir = 81236 }"instructions::rpc::handle_line::ping" = { ir = 6885 }"instructions::session::canonical_json::nested" = { ir = 1138903 }"instructions::session::decode::linear_1000" = { ir = 11056510 }"instructions::session::decode::tool_calls_1000" = { ir = 10284262 }"instructions::session::encode::linear_1000" = { ir = 5736448 }"instructions::session::encode::tool_calls_1000" = { ir = 5133175 }"instructions::session::fork_at::linear_1000" = { ir = 232844 }"instructions::session::from_frames::linear_1000" = { ir = 1392615 }"startup::cli::smith::eval_mock" = { ir = 1156689 }"startup::cli::smith::help" = { ir = 741164 }"instructions::agent::run_turn::history_1000_masked" = { ir = 11384108 }"instructions::providers::sse::anthropic" = { ir = 119257 }"instructions::providers::sse::gemini" = { ir = 52389 }"instructions::providers::sse::openai" = { ir = 89745 }"instructions::rpc::handle_line::ping" = { ir = 8428 }"instructions::session::canonical_json::nested" = { ir = 1122300 }"instructions::session::decode::linear_1000" = { ir = 11152010 }"instructions::session::decode::tool_calls_1000" = { ir = 10396988 }"instructions::session::encode::linear_1000" = { ir = 5674199 }"instructions::session::encode::tool_calls_1000" = { ir = 5302087 }"instructions::session::fork_at::linear_1000" = { ir = 233231 }"instructions::session::from_frames::linear_1000" = { ir = 1388558 }"startup::cli::smith::eval_mock" = { ir = 1196624 }"startup::cli::smith::help" = { ir = 707441 }+70 / −13 text lines
if fs::write(BUDGETS, render_budgets(&pinned, &toolchain)).is_err() { if fs::write(BUDGETS, render_budgets(&pinned, &platform)).is_err() { // Instruction counts belong to one toolchain and libc: the gate runs // where the pins were taken (the CI image); elsewhere the run reports. let pinned_on = fs::read_to_string(BUDGETS) .ok() .and_then(|text| pinned_platform(&text)); if pinned_on.as_deref() != Some(platform.as_str()) { note(&format!( "perf: pins belong to `{}`, this run is `{platform}`; counts reported in target/report/perf.md, gate skipped\n", pinned_on.as_deref().unwrap_or("no platform") )); return ExitCode::SUCCESS; } .args(["--", "--save-summary=json", "--output-format=json"])fn render_budgets(pins: &BTreeMap<String, u64>, toolchain: &str) -> String {/// The platform named in a budgets file header, if any.fn pinned_platform(text: &str) -> Option<String> { text.lines() .find_map(|line| line.trim().strip_prefix("# Pinned with ")) .map(|rest| rest.trim_end_matches('.').to_string())}fn render_budgets(pins: &BTreeMap<String, u64>, platform: &str) -> String { "# Callgrind instruction budgets (Ir) per bench, gated within ±{BAND_PERCENT} % by `cargo x perf`.\n\ Toolchain: `{toolchain}`.\n\n| bench | ir | pin | delta |\n|---|---|---|---|\n" Platform: `{platform}`.\n\n| bench | ir | pin | delta |\n|---|---|---|---|\n"/// `rustc --version` of the toolchain building the benches.fn toolchain() -> String { Command::new("rustc")/// What instruction counts depend on: the toolchain building the benches/// and the libc they link, e.g. `rustc 1.98.1 (…) | glibc 2.41`.fn platform() -> String { format!("{} | {}", tool_first_line("rustc"), libc_version())}fn tool_first_line(program: &str) -> String { Command::new(program) .and_then(|output| { String::from_utf8_lossy(&output.stdout) .lines() .next() .map(str::to_string) }) .unwrap_or_else(|| format!("{program} version unavailable"))}/// `glibc <version>` from `ldd --version`, whose first line ends with the/// version on every glibc distribution; other libcs report as unknown.fn libc_version() -> String { let line = tool_first_line("ldd"); line.rsplit(' ') .next() .filter(|last| last.starts_with(|c: char| c.is_ascii_digit())) const FIRST_RUN: &str = r#"{"baselines":[null,null],"details":"(linear(1000))","function_name":"encode","id":"linear_1000","kind":"LibraryBenchmark","module_path":"instructions::session::encode","profiles":[{"summaries":{"parts":[{"details":{"Left":{"pid":1,"thread":1}},"metrics_summary":{"Callgrind":{"Ir":{"diffs":null,"metrics":{"Left":{"Int":999}}}}}}],"total":{"regressions":[],"summary":{"Callgrind":{"Ir":{"diffs":null,"metrics":{"Left":{"Int":5736448}}}}}}},"tool":"Callgrind"}],"version":"6"}"#; #[test] fn pinned_platform_reads_the_header() { let text = "# x\n# Pinned with rustc 1.98.1 (a 2026) | glibc 2.41.\n[budgets]\n"; assert_eq!( super::pinned_platform(text).as_deref(), Some("rustc 1.98.1 (a 2026) | glibc 2.41") ); assert_eq!(super::pinned_platform("[budgets]\n"), None); }