Repository navigation
fix(criterion): initialize instrument hooks before the batched timed span - #211
Conversation
569a7a8 to
bc65006
Compare
Merging this PR will degrade performance by 0.01%5 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
…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.
bc65006 to
ef17e8c
Compare
[Low impact] The PR appears safe to merge. SummaryMoves hook initialization before the timer in synchronous and asynchronous
Reviews (1) · Last reviewed commit: "fix(criterion): initialize instrument ho..." · Reviewed by Greptile |
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) takeInstrumentHooks::instance()once beforetime_startand reuse it in the loop.iter_with_setup,iter_with_large_dropanditer_with_large_setuproute through these.iter/iter_customwere already fine: they callinstance()afterelapsed_timeis taken.instance()that the first call must happen outside timed regions.Reproducer from #210 with stale
/tmp/runner.{ctl,ack}.fifo:firstsecondThe ~4 s init stall still happens until CodSpeedHQ/instrument-hooks#36 lands; it no longer affects results.
Fixes #210