Skip per-tick sampling of profiler-internal threads#5955
Conversation
|
6656528 to
3b3cf59
Compare
|
In the |
10efbe0 to
b3d4ae0
Compare
|
Before: After: cpu_sampling_overhead and serialization_overhead drop and all regular samples are skipped for the 2 profiler-internal threads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3d4ae0f42
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
BenchmarksBenchmark execution time: 2026-07-01 10:02:43 Comparing candidate commit 22d15f8 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 47 metrics, 1 unstable metrics.
|
b3d4ae0 to
4909597
Compare
ivoanjo
left a comment
There was a problem hiding this comment.
This is cool! I'm a bit meh about having the CpuAndWallTimeWorker doing a "fake-serialize" to still get the overhead on those threads so I've suggested an alternative ;)
ivoanjo
left a comment
There was a problem hiding this comment.
Gave it a pass, I think almost almost there!
09c443e to
cabb464
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cabb4640bd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
cabb464 to
eaa56fa
Compare
ivoanjo
left a comment
There was a problem hiding this comment.
👍 LGTM, There's just the tiny change to the thread_done call and otherwise let's get this in!
eaa56fa to
0d9a6b5
Compare
CpuAndWallTimeWorker and IdleSamplingHelper threads are now sampled only once per profiling period (via the on-serialize flush) instead of every 10ms tick, reducing profiling overhead. Skip record_sampling_overhead for profiler-internal threads since their timestamps are not updated during per-tick sampling. Seed cpu/wall timestamps when marking a thread as profiler-internal, so the first reporting period produces a real delta instead of zero (INVALID_TIME would cause update_time_since_previous_sample to return 0, losing the entire first period). Each profiler-internal thread records its own final sample before dying via rb_ensure. The worker thread calls profiler_internal_thread_done() in the cleanup path after rb_protect returns. The idle helper wraps its loop body in rb_ensure to guarantee the flush even on exception, receiving the thread_context_collector as an argument — the Ruby reference on the stack keeps it alive, so no GC marking is needed in the native struct. This eliminates the race where the idle helper thread might not have been scheduled yet when on_serialize was called from #stop. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…GVL_INSTRUMENTATION guard This testing helper manipulates per-thread timestamps and is not GVL-specific. Having it inside the #ifndef guard made it unavailable on Ruby <= 3.1, breaking the profiler-internal thread skipping test. Co-Authored-By: Claude Opus 4.6 <[email protected]>
51be165 to
22d15f8
Compare
CpuAndWallTimeWorker and IdleSamplingHelper threads are now sampled only once per profiling period (via the on-serialize flush) instead of every 10ms tick, reducing profiling overhead.
What does this PR do?
^
Motivation:
Reduce profiler overhead
Change log entry
Yes, Changed: Profiling: Reduce profiler overhead by sampling profiler-internal threads only once per minute.
Additional Notes:
How to test the change?