From 32a53216480bf7cd7b3181e98e43c45d68f329ec Mon Sep 17 00:00:00 2001 From: Yori Date: Thu, 3 Dec 2026 18:38:20 -0500 Subject: [PATCH 1/2] Record a digest of the footprint programs in the workload The workload record carries the call count and total source bytes, which an edit that keeps a fixture's length, or a reordering, leaves unchanged. Add an FNV-1a digest of the ordered program names and sources, each length-framed so bytes moved across a boundary change it too. VIBE-239 --- examples/footprint.rs | 60 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/examples/footprint.rs b/examples/footprint.rs index 7714ef481..ee4f2481d 100644 --- a/examples/footprint.rs +++ b/examples/footprint.rs @@ -39,6 +39,22 @@ impl Stage { } } +/// Identifies the ordered program names and sources, so a paired run can +/// confirm that both revisions measured the same workload. +fn programs_digest(programs: &[(&str, &str)]) -> String { + // FNV-1a, with each name and source preceded by its length so bytes moved + // across a boundary change the digest. + let mut hash = 0xcbf29ce484222325_u64; + for (name, source) in programs { + for part in [name.as_bytes(), source.as_bytes()] { + for byte in (part.len() as u64).to_le_bytes().iter().chain(part) { + hash = (hash ^ u64::from(*byte)).wrapping_mul(0x100000001b3); + } + } + } + format!("{hash:016x}") +} + fn registered(engine: &mut Engine) -> vibescript::Result> { let mut capabilities = Vec::new(); for name in ["log_event", "metric", "lookup", "publish"] { @@ -168,7 +184,49 @@ fn main() -> Result<(), Box> { println!( "{}", serde_json::json!({"calls": 1000, "steps": steps, "tracked_peak_bytes": peak, - "tracked_retained_bytes_sum": retained, "source_bytes": programs::PROGRAMS.iter().map(|(_, source)| source.len()).sum::()}) + "tracked_retained_bytes_sum": retained, "source_bytes": programs::PROGRAMS.iter().map(|(_, source)| source.len()).sum::(), + "programs_digest": programs_digest(&programs::PROGRAMS)}) ); Ok(()) } + +#[cfg(test)] +mod tests { + use super::programs_digest; + + const PROGRAMS: [(&str, &str); 2] = [ + ("a.vibe", "def run\n 1\nend\n"), + ("b.vibe", "def run\n 2\nend\n"), + ]; + + #[test] + fn digest_changes_with_a_same_length_source_edit() { + let edited = [PROGRAMS[0], ("b.vibe", "def run\n 3\nend\n")]; + assert_ne!(programs_digest(&PROGRAMS), programs_digest(&edited)); + } + + #[test] + fn digest_changes_with_program_order() { + let reordered = [PROGRAMS[1], PROGRAMS[0]]; + assert_ne!(programs_digest(&PROGRAMS), programs_digest(&reordered)); + } + + #[test] + fn digest_changes_with_a_renamed_program() { + let renamed = [PROGRAMS[0], ("c.vibe", PROGRAMS[1].1)]; + assert_ne!(programs_digest(&PROGRAMS), programs_digest(&renamed)); + } + + #[test] + fn digest_changes_when_bytes_cross_a_boundary() { + // Each pair concatenates to the same bytes. + assert_ne!( + programs_digest(&[("ab", "c")]), + programs_digest(&[("a", "bc")]) + ); + assert_ne!( + programs_digest(&[("a", "xy"), ("b", "z")]), + programs_digest(&[("a", "x"), ("yb", "z")]) + ); + } +} From 31dc6a6068c718b8b78dcb2435105c2c3bdfcd62 Mon Sep 17 00:00:00 2001 From: Yori Date: Thu, 3 Dec 2026 18:38:20 -0500 Subject: [PATCH 2/2] Compare the programs digest in paired footprint runs A paired run compared only the call count and source bytes, so a fixture edited without changing its length, or reordered, would let the report attribute a workload difference to the compiler change. Compare the digest too, and name the differing key in the failure. A baseline from before the digest is rejected rather than taken as matching. VIBE-239 --- benchmarks/README.md | 7 +++++-- scripts/footprint.py | 5 +++-- scripts/test_footprint.py | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index cb54c6f63..e81999412 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -85,8 +85,11 @@ CARGO_BUILD_JOBS=4 python3 scripts/footprint.py --rounds 8 --check --out .cache/ Pass `--baseline /path/to/previous/output` to alternate preserved baseline and current binaries in fresh processes. The tool verifies baseline binary hashes, -the full compiler identity (including distribution) and `RUSTFLAGS`, then writes -the new baseline samples and summary under `baseline/` in the output. Each +the full compiler identity (including distribution) and `RUSTFLAGS`. After +measuring, it checks that both binaries ran the same workload: the call count, +the source bytes, and a digest of the ordered program names and sources, so an +edited or reordered fixture can't pass as a compiler change. It then writes the +new baseline samples and summary under `baseline/` in the output. Each executable receives one unmeasured launch before the measured rounds so a freshly copied binary does not skew round 0, and paired preparation ends on the candidate so block 0 sees the same preceding-binary transition as later blocks. diff --git a/scripts/footprint.py b/scripts/footprint.py index 3a2db4ea1..c804b7616 100644 --- a/scripts/footprint.py +++ b/scripts/footprint.py @@ -153,8 +153,9 @@ def main(): if baseline: baseline_summary = json.loads((baseline / "summary.json").read_text()) previous = summarize(baseline_samples, baseline_summary["stripped_vibes_bytes"], paired=True) - for key in ["calls", "source_bytes"]: - assert previous["workload"][key] == summary["workload"][key], "baseline workload differs" + for key in ["calls", "source_bytes", "programs_digest"]: + baseline_value = previous["workload"].get(key) + assert baseline_value == summary["workload"][key], f"baseline workload {key} {baseline_value!r} differs from {summary['workload'][key]!r}" baseline_environment["measurement_command"] = sys.argv if "cpu_affinity" in environment: baseline_environment["measurement_cpu_affinity"] = environment["cpu_affinity"] diff --git a/scripts/test_footprint.py b/scripts/test_footprint.py index b61e8ffd5..984ca0765 100644 --- a/scripts/test_footprint.py +++ b/scripts/test_footprint.py @@ -76,10 +76,21 @@ def setup_fake_repo(root: Path, footprint_body: str) -> dict[str, str]: "tracked_peak_bytes": 20, "tracked_retained_bytes_sum": 30, "source_bytes": 40, + "programs_digest": "0123456789abcdef", })) """.lstrip() +def workload_body(programs_digest: str | None) -> str: + """A fake footprint binary whose workload reports the given programs digest.""" + workload = {"calls": 1000, "steps": 10, "tracked_peak_bytes": 20, "tracked_retained_bytes_sum": 30, "source_bytes": 40} + if programs_digest is not None: + workload["programs_digest"] = programs_digest + stage = {"stage": "compiled_1", "allocations": 100, "allocated_bytes": 1000, "live_bytes": 500, + "peak_live_bytes": 800, "rss_bytes": 4096, "elapsed_ns": 400_000} + return f"import json\nprint(json.dumps({stage!r}))\nprint(json.dumps({workload!r}))\n" + + class FootprintDriverTests(unittest.TestCase): def test_budget_failure_reports_both_captured_streams(self): with tempfile.TemporaryDirectory() as directory: @@ -222,6 +233,37 @@ def test_paired_run_prepares_both_binaries_and_removes_first_launch_spike(self): self.assertEqual(json.loads((root / "paired/summary.json").read_text()), cand_summary) self.assertEqual(json.loads((root / "paired/baseline/summary.json").read_text()), base_summary) + def test_paired_run_rejects_a_baseline_with_different_programs(self): + # An edited fixture of the same length keeps the call count and source + # bytes, so only the programs digest tells the revisions apart. A + # baseline from before the digest was recorded can't show it matches. + for baseline_digest in ["fedcba9876543210", None]: + with self.subTest(baseline_digest=baseline_digest), tempfile.TemporaryDirectory() as directory: + root = Path(directory) + env = setup_fake_repo(root, workload_body(baseline_digest)) + base_run = subprocess.run( + [sys.executable, "scripts/footprint.py", "--out", "base", "--rounds", "2"], + cwd=root, + env=env, + capture_output=True, + text=True, + ) + self.assertEqual(base_run.returncode, 0, base_run.stdout + base_run.stderr) + write_script(root / "target/release/examples/footprint", workload_body("0123456789abcdef")) + + paired_run = subprocess.run( + [sys.executable, "scripts/footprint.py", "--out", "paired", "--baseline", "base", "--rounds", "2"], + cwd=root, + env=env, + capture_output=True, + text=True, + ) + self.assertNotEqual(paired_run.returncode, 0, paired_run.stdout + paired_run.stderr) + self.assertIn( + f"baseline workload programs_digest {baseline_digest!r} differs from '0123456789abcdef'", + paired_run.stderr, + ) + if __name__ == "__main__": unittest.main()