Skip to content

Fix timer fast path starvation when used as a yield point#135

Merged
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/follow-ups
Feb 12, 2026
Merged

Fix timer fast path starvation when used as a yield point#135
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/follow-ups

Conversation

@sgerbino
Copy link
Collaborator

@sgerbino sgerbino commented Feb 12, 2026

The already-expired timer fast path used dispatch() which does symmetric transfer on the same thread, resuming the coroutine without yielding to the scheduler. This starved queued work (e.g. sub-tasks spawned via run_async) when a 0ns timer was used as a poll/yield mechanism.

Switch to post() + noop_coroutine() so the coroutine enters the scheduler queue, giving other pending work a chance to execute.

Summary by CodeRabbit

  • Performance
    • Optimized timer handling for already-expired timers to yield to the scheduler, allowing other queued work to execute and improving overall responsiveness.

The already-expired timer fast path used dispatch() which does
symmetric transfer on the same thread, resuming the coroutine
without yielding to the scheduler. This starved queued work
(e.g. sub-tasks spawned via run_async) when a 0ns timer was
used as a poll/yield mechanism.

Switch to post() + noop_coroutine() so the coroutine enters the
scheduler queue, giving other pending work a chance to execute.
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This change modifies the timer service's already-expired timer handling in timer_impl::wait. When a timer has expired (heap index at max and expiry <= now), the coroutine is now posted to the executor instead of dispatched, yielding to the scheduler. The comment describing this behavior is updated accordingly.

Changes

Cohort / File(s) Summary
Timer Service Fast Path
src/corosio/src/detail/timer_service.cpp
Modified already-expired timer handling to use post() instead of dispatch() for executor submission, allowing scheduler yields. Updated accompanying comment. Error output still set when applicable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • PR #112: Modifies timer_impl::wait to short-circuit already-expired timers by posting coroutines to the executor, implementing a similar optimization pattern.

Poem

🐰 A timer once eager to run,
Now learns patience—the scheduler's fun!
Post, not dispatch, let others play,
Fair scheduling wins the day! ✨

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix timer fast path starvation when used as a yield point' directly and clearly describes the main change: addressing a starvation issue in the timer fast path when used as a yield mechanism.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.15%. Comparing base (9ed1f7d) to head (c739b1e).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #135      +/-   ##
===========================================
+ Coverage    80.93%   81.15%   +0.21%     
===========================================
  Files           64       64              
  Lines         5666     5667       +1     
===========================================
+ Hits          4586     4599      +13     
+ Misses        1080     1068      -12     
Files with missing lines Coverage Δ
src/corosio/src/detail/timer_service.cpp 87.22% <100.00%> (+0.03%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ed1f7d...c739b1e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cppalliance-bot
Copy link

An automated preview of the documentation is available at https://135.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-02-12 16:11:05 UTC

@cppalliance-bot
Copy link

GCOVR code coverage report https://135.corosio.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://135.corosio.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://135.corosio.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-02-12 16:19:33 UTC

@sgerbino sgerbino merged commit 388d4b7 into cppalliance:develop Feb 12, 2026
17 checks passed
@sgerbino sgerbino deleted the pr/follow-ups branch February 12, 2026 16:20
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.

2 participants