Avoid heap-allocating background processor futures#4733
Conversation
Abeeujah
commented
Jun 20, 2026
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.
|
I've assigned @valentinewallace as a reviewer! |
|
No functional issues found. I reviewed the refactor carefully against the original behavior:
Cross-cutting note (not blocking): the |
| let fut = async { | ||
| let needs_cm_persist = channel_manager.get_cm().get_and_clear_needs_persistence(); | ||
| // Captured by the ChannelManager persistence future below. Only meaningful when | ||
| // `needs_cm_persist` is set, Declared before the futures so it outlives them |
There was a problem hiding this comment.
Just a nit: wouldn't it be better if it is "needs_cm_persist is set. Declared..." or "needs_cm_persist is set, declared..." if we will still go with the comma.