Skip to content

fix(core): seed the V8 RNG and string hashes in walltime mode - #105

Draft
not-matthias wants to merge 1 commit into
cod-3936-add-always-sparkplug-to-codspeed-node-analysis-mode-v8-flagsfrom
cod-3936-walltime-random-seed
Draft

not-matthias wants to merge 1 commit into
cod-3936-add-always-sparkplug-to-codspeed-node-analysis-mode-v8-flagsfrom
cod-3936-walltime-random-seed

Conversation

@not-matthias

Copy link
Copy Markdown
Member

Walltime mode now passes the same seed flags as analysis mode: --hash-seed=1 and --random-seed=1, plus --no-randomize-hashes on Node.js < 18. Both modes get them from one shared helper. Disabled mode stays unseeded, so runs outside CodSpeed keep the normal behavior.

Without these flags, every walltime process used a random Math.random() seed and a random hash seed. Benchmarks that use random inputs, or that depend on hash table layout (collisions, lookup cost), could vary between runs for reasons that have nothing to do with the code under test.

Checked on Node.js 24:

  • Math.random() returns the same sequence on every run, including in worker threads and in vitest walltime forks.
  • --hash-seed still applies even though Node boots from a snapshot, because --rehash-snapshot is on by default. With seed 1 the internal dictionary layout of the same object is identical across runs. Seed 2 gives a different but stable layout, and no flag gives a different layout each run.
  • crypto randomness and key iteration order are unchanged.

--predictable and the GC flags stay analysis-only, because they change walltime timing.

The runner's exec-harness node wrapper copies these flags by hand and needs the same walltime update. Until then, checkV8Flags will warn about the missing seed flags under codspeed exec.

Stacked on #104.

Refs COD-3936

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.
@codspeed

codspeed Bot commented Oct 23, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 1.13%

3 warnings, 1 note

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 13 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

ℹ️ 16 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 4 improved benchmarks
❌ 6 regressed benchmarks
✅ 254 untouched benchmarks
⏩ 56 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation wait 500ms 27.1 ms 48.4 ms -44%
❌ CPU Simulation wait 1sec 54.2 ms 91.3 ms -40.65%
❌ CPU Simulation test_recursive_fibo_10 339 µs 513.2 µs -33.94%
❌ CPU Simulation wait 500ms 27.1 ms 31.8 ms -14.83%
❌ CPU Simulation wait 1sec 55.7 ms 64.4 ms -13.54%
❌ Walltime switch 2 84 ns 96 ns -12.5%
⚡ CPU Simulation switch 1 657.1 µs 310.2 µs ×2.1
⚡ CPU Simulation recursive fibo 10 685.3 µs 339.9 µs ×2
⚡ Memory wait 500ms 28.7 KB 22.7 KB +26.54%
⚡ Walltime switch 1 84 ns 72 ns +16.67%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cod-3936-walltime-random-seed (c40ae87) with cod-3936-add-always-sparkplug-to-codspeed-node-analysis-mode-v8-flags (8dcd85b)

Open in CodSpeed

Footnotes

  1. 56 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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