Avoid heap-allocating background processor futures#4733
Conversation
Abeeujah
commented
Jun 20, 2026
|
I've assigned @valentinewallace as a reviewer! |
|
I've re-examined the full refactored persistence loop against the original control flow. Verified:
No new issues found beyond what was raised in the prior review pass (the No issues found. |
|
🔔 1st Reminder Hey @valentinewallace! This PR has been waiting for your review. |
| // Captured by the ChannelManager persistence future below. Only meaningful when | ||
| // `needs_cm_persist` is set, declared before the futures so it outlives them | ||
| // (drop order). | ||
| let pending_monitor_writes = |
There was a problem hiding this comment.
This can stay in the if/future and avoid the if.
| let mut waker = dummy_waker(); | ||
| let mut ctx = task::Context::from_waker(&mut waker); | ||
| match core::pin::Pin::new(&mut fut).poll(&mut ctx) { | ||
| task::Poll::Ready(res) => futures.set_a_res(res), |
There was a problem hiding this comment.
I don't believe there's any reason to change this, it would probably be simpler to keep the code structured the way it was.
There was a problem hiding this comment.
I've simplified it, although, I couldn't fully restore the original now that the futures are stack-pinned, Joiner holds Pin<&mut> references into them and so must be declared after all of them.
Meaning it doesn't exist yet at the eager-poll site, so the outcome has to be stashed and fed in once the Joiner is constructed. Open to a cleaner approach if you have any recommendations.
Replace Box::pin with core::pin::pin! in process_events_async now that MSRV is 1.75. This eliminates a heap allocation per task on every loop iteration by pinning the futures directly to the stack. To satisfy lifetime and Joiner bounds, the loop logic was refactored to run synchronous timer checks first, using flags to conditionally execute the stack-pinned futures. Existing eager polling and early-break semantics are preserved.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4733 +/- ##
==========================================
+ Coverage 84.54% 86.25% +1.70%
==========================================
Files 137 160 +23
Lines 77617 111579 +33962
Branches 77617 111579 +33962
==========================================
+ Hits 65625 96241 +30616
- Misses 9949 12694 +2745
- Partials 2043 2644 +601
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|