7834: runtime: avoid redundant unpark in current_thread scheduler#44
7834: runtime: avoid redundant unpark in current_thread scheduler#44martin-augment wants to merge 2 commits intomasterfrom
Conversation
Checking if there is pending work in `park()` ensures that if a `before_park` hook populates the deferred queue (e.g. via `yield_now()`), the runtime skips the blocking sleep. This also refactors the loop to use a common `has_pending_work` helper.
WalkthroughThe changes modify Tokio's current-thread runtime scheduler to improve parking and waking behavior. A new internal helper method consolidates checks for pending work across the scheduler. The parking logic is updated to use this consolidated check, and the wake_on_fork mechanism is hardened to avoid redundant unpark operations when the current thread already holds the wake signal. Atomic Ordering imports are extended to support the new synchronization requirements. Test additions and modifications validate the updated scheduling behavior for cross-thread waking and before-park hooks. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: 2025-11-04T09:48:44.541ZApplied to files:
🧬 Code graph analysis (3)tokio/tests/rt_metrics.rs (1)
tokio/tests/rt_basic.rs (4)
tokio/tests/rt_common_before_park.rs (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (9)
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. Comment |
Pull Request Review - PR #44SummaryThis PR addresses an important issue in the current_thread scheduler where redundant unpark operations were being performed. The changes introduce two key optimizations:
Code Quality & Best Practices ✅Strengths:
Observations:
Correctness Analysis ✅Runtime Logic:
Potential Issues:
Performance Considerations ✅Improvements:
Memory Ordering:
Security Concerns ✅No security issues identified. The changes:
Test Coverage ⭐Excellent Coverage:The PR includes three comprehensive test files:
Test Quality:
Minor Suggestions:
Additional NotesImport Addition:The addition of Metrics Test Change:The change in
Verdict: ✅ ApproveThis is a solid optimization with:
The changes are well-thought-out and address a real inefficiency in the scheduler. The commit messages clearly explain the rationale. Great work! Nits (non-blocking):
Review generated by Claude Code |
🤖 Augment PR SummarySummary: This PR reduces redundant wake-ups in the Changes:
Technical Notes: The new logic relies on the existing 🤖 Was this summary useful? React with 👍 or 👎 |
| // This check will fail if `before_park` spawns a task for us to run | ||
| // instead of parking the thread | ||
| if core.tasks.is_empty() { | ||
| if !self.has_pending_work(&core) { |
There was a problem hiding this comment.
value:good-to-have; category:documentation; feedback:The Augment AI reviewer is correct! The simple condition has been replaced with a call to a method that makes checks three conditions, so the comment above is no more valid and it needs to be updated. Prevents making the comment obsolete and incomplete.
7834: To review by AI