From 5e52a1d13fd87efbad684ef12182d2ae710cb7f9 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Fri, 23 Oct 2026 18:06:15 +0200 Subject: [PATCH] fix(core): seed the V8 RNG and string hashes in walltime mode Walltime runs left Math.random() and V8's hash seed random per process, so benchmarks using random inputs or hash-heavy structures varied between runs for reasons unrelated to the code under test. Pass the analysis-mode seed flags (--hash-seed=1, --random-seed=1, and --no-randomize-hashes on Node < 18) in walltime too, via one shared helper. Disabled mode stays unseeded. crypto randomness and key iteration order are unchanged. --- packages/core/src/introspection.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/src/introspection.ts b/packages/core/src/introspection.ts index 18c29ba0..8906c1d9 100644 --- a/packages/core/src/introspection.ts +++ b/packages/core/src/introspection.ts @@ -7,6 +7,15 @@ const CUSTOM_INTROSPECTION_EXIT_CODE = 0; const V8_LOG_FILENAME_PATTERN = "codspeed-v8-%p.log"; +// Fixed seeds so Math.random() and hash table layout match on every run +const getSeedFlags = (nodeVersionMajor: number) => { + const flags = ["--hash-seed=1", "--random-seed=1"]; + if (nodeVersionMajor < 18) { + flags.push("--no-randomize-hashes"); + } + return flags; +}; + export const getV8Flags = () => { const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); const instrumentMode = getInstrumentMode(); @@ -17,8 +26,7 @@ export const getV8Flags = () => { case "analysis": { flags.push( ...[ - "--hash-seed=1", - "--random-seed=1", + ...getSeedFlags(nodeVersionMajor), "--no-opt", "--always-sparkplug", "--predictable", @@ -28,9 +36,6 @@ export const getV8Flags = () => { "--max-old-space-size=4096", ], ); - if (nodeVersionMajor < 18) { - flags.push("--no-randomize-hashes"); - } if (nodeVersionMajor < 20) { flags.push("--no-scavenge-task"); } else { @@ -48,6 +53,8 @@ export const getV8Flags = () => { } case "walltime": { + flags.push(...getSeedFlags(nodeVersionMajor)); + // Emit the V8 jitdump flags.push("--perf-prof");