Use five launches for Default benchmark jobs

Merged
BR
17d ago
+10-4

Motivation

Benchmark results for the same build swing 10-25% per case between BenchmarkDotNet runs. Each benchmark process settles into one of two performance modes for its whole lifetime. For DecompressAll on geo.protodata on .NET 11 that is about 22 us or about 27-30 us. BenchmarkDotNet's Default job uses one launch per case, so a run measured whichever mode it happened to get, and A/B comparisons were unreliable.

Cause

Investigated with an out-of-process harness that mirrors DecompressAll, one factor at a time over 10+ launches:

  • The mode is set per process and holds for the life of the process. Two processes running at the same time on different cores land in different modes independently, so it is not machine load.
  • Ruled out: alignment of the lookback, SnappyStream input and caller buffers (pinned at fixed offsets mod 64 and mod 4096), stack alignment, OSR, ReadyToRun alone, E-core scheduling, and JIT code placement.
  • Under default tiering with Dynamic PGO, the final Tier1 code for SnappyDecompressor.DecompressAllTags differs in every launch (block layout and branch shapes change with the inlinees' timing-dependent profile data). With DOTNET_TieredCompilation=0 and DOTNET_ReadyToRun=0, 21 of 21 launches were fast.

This is JIT behavior, not buffer alignment in Snappier, so MemoryRandomization would not help. Moving cold paths out of DecompressAllTags with NoInlining was also tried: it did not remove the slow mode, and moving IncrementalCopy's near-end paths out of line cost 15-17%. No library change is included.

Change

Default-based configs (Frameworks, Version Comparison, Basic, x86/x64) now use Job.Default.WithLaunchCount(5), so each result covers the mix of modes. Short configs keep one launch.

Results

Two back-to-back Basic Default runs of DecompressAll on net11.0, same build:

  • Per-launch means show the modes are now sampled, e.g. one geo.protodata launch at 27.7 us beside 21.8-22.2 us.
  • 5 of 11 cases agree within their error margins, geo.protodata among them. The others show a shift across the whole run (urls.10K was 351-357 us in every launch of one run and 336-347 us in every launch of the other), which more launches cannot remove. BenchmarkDotNet's error is computed from pooled iterations, so it understates launch-to-launch variance.
  • A Default run of DecompressAll now takes about 17 minutes.

šŸ¤– Generated with Claude Code