Skip to content

fix(criterion): initialize instrument hooks before the batched timed span - #211

Merged
not-matthias merged 1 commit into
mainfrom
cod-4460-fix-fifo-issues-reported-by-firefox
Nov 26, 2026
Merged

not-matthias merged 1 commit into
mainfrom
cod-4460-fix-fifo-issues-reported-by-firefox

Conversation

@not-matthias

@not-matthias not-matthias commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

TLDR: The first InstrumentHooks::instance() call initializes the hooks, and in the criterion walltime fork's batched routines it ran inside the timed span. A slow init (~4 s with stale runner FIFOs) flipped the first bench to flat sampling and inflated its result. The routines now take the hooks instance before the timer starts.

  • iter_batched / iter_batched_ref (sync and async) take InstrumentHooks::instance() once before time_start and reuse it in the loop. iter_with_setup, iter_with_large_drop and iter_with_large_setup route through these.
  • iter / iter_custom were already fine: they call instance() after elapsed_time is taken.
  • Document on instance() that the first call must happen outside timed regions.

Reproducer from #210 with stale /tmp/runner.{ctl,ack}.fifo:

first second
before (from #210) flat, 100 iters, 2.0001 ms linear, 1.1448 ms
after linear, 5050 iters, 1.1485 ms linear, 5050 iters, 1.1460 ms

The ~4 s init stall still happens until CodSpeedHQ/instrument-hooks#36 lands; it no longer affects results.

Fixes #210

@not-matthias
not-matthias force-pushed the cod-4460-fix-fifo-issues-reported-by-firefox branch from 569a7a8 to bc65006 Compare November 26, 2026 10:27
@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.01%

5 warnings, 1 note

⚠️ Unable to measure the execution of 59 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ 17 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

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

⚠️ 169 benchmarks are too noisy to detect regressions

Their results vary so much between runs that only very large changes would be flagged. Investigate what causes this variance to catch their regressions.

See affected benchmarks

ℹ️ 57 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. (9 benchmarks)
  • The flamegraph wasn't generated: no execution data was recorded while the benchmark ran. Make sure the compiler didn't optimize the benchmark out. (48 benchmarks)

See affected benchmarks

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 613 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Walltime string_processing_multi_counter 355 ns 742 ns -52.16%
❌ Walltime large_setup 9 ns 15 ns -40%
❌ Walltime zeroed_buffer[1] 49 µs 50.8 µs -3.59%
⚡ Walltime add_two_integers[(42, 13)] 19 ns 6 ns ×3.2
⚡ CPU Simulation spawn_on_parent_runtime 69.2 µs 60.7 µs +14.04%

Tip

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


Comparing cod-4460-fix-fifo-issues-reported-by-firefox (ef17e8c) with main (6ab62f6)

Open in CodSpeed

…span

The first InstrumentHooks::instance() call initializes the hooks, which does
IPC with the runner and can be slow (about 4 s with stale runner FIFOs). In the
criterion walltime fork, iter_batched and iter_batched_ref (sync and async)
made that first call inside the span that becomes elapsed_time. The first
batched bench in a process then had the init time added to its warm-up, so
criterion switched it to flat sampling and reported a higher time.

Take the hooks instance once before time_start in these routines and reuse it
in the loop. Document on instance() that the first call must happen outside
timed regions.
@not-matthias not-matthias changed the title fix: initialize instrument hooks before timed regions fix(criterion): initialize instrument hooks before the batched timed span Nov 26, 2026
@not-matthias
not-matthias force-pushed the cod-4460-fix-fifo-issues-reported-by-firefox branch from bc65006 to ef17e8c Compare November 26, 2026 10:40
@not-matthias
not-matthias marked this pull request as ready for review November 26, 2026 10:41
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Moves hook initialization before the timer in synchronous and asynchronous iter_batched and iter_batched_ref. Each loop reuses that hooks reference.

  • Batched Criterion loops start timing only after hooks are ready.

Reviews (1) · Last reviewed commit: "fix(criterion): initialize instrument ho..." · Reviewed by Greptile

@not-matthias
not-matthias merged commit a4cf5ba into main Nov 26, 2026
50 of 51 checks passed
@not-matthias
not-matthias deleted the cod-4460-fix-fifo-issues-reported-by-firefox branch November 26, 2026 15:10
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.

criterion-compat walltime: InstrumentHooks init is timed in iter_batched warm-up and can flip the first bench to flat sampling

2 participants