Skip to content

Commit 5e52a1d

Browse files
committed
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.
1 parent 8ecc3ba commit 5e52a1d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎packages/core/src/introspection.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ const CUSTOM_INTROSPECTION_EXIT_CODE = 0;
77

88
const V8_LOG_FILENAME_PATTERN = "codspeed-v8-%p.log";
99

10+
// Fixed seeds so Math.random() and hash table layout match on every run
11+
const getSeedFlags = (nodeVersionMajor: number) => {
12+
const flags = ["--hash-seed=1", "--random-seed=1"];
13+
if (nodeVersionMajor < 18) {
14+
flags.push("--no-randomize-hashes");
15+
}
16+
return flags;
17+
};
18+
1019
export const getV8Flags = () => {
1120
const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]);
1221
const instrumentMode = getInstrumentMode();
@@ -17,8 +26,7 @@ export const getV8Flags = () => {
1726
case "analysis": {
1827
flags.push(
1928
...[
20-
"--hash-seed=1",
21-
"--random-seed=1",
29+
...getSeedFlags(nodeVersionMajor),
2230
"--no-opt",
2331
"--always-sparkplug",
2432
"--predictable",
@@ -28,9 +36,6 @@ export const getV8Flags = () => {
2836
"--max-old-space-size=4096",
2937
],
3038
);
31-
if (nodeVersionMajor < 18) {
32-
flags.push("--no-randomize-hashes");
33-
}
3439
if (nodeVersionMajor < 20) {
3540
flags.push("--no-scavenge-task");
3641
} else {
@@ -48,6 +53,8 @@ export const getV8Flags = () => {
4853
}
4954

5055
case "walltime": {
56+
flags.push(...getSeedFlags(nodeVersionMajor));
57+
5158
// Emit the V8 jitdump
5259
flags.push("--perf-prof");
5360

0 commit comments

Comments
 (0)