lambdaclass / lambdaclass/spawned
perf: replace threads 100ms polling loop with poison-pill shutdown
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 59
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
Parent issue
Part of #156 (performance audit findings).
Problem
threads/actor.rs uses rx.recv_timeout(Duration::from_millis(100)) in the message loop to periodically check cancellation_token.is_cancelled():
match rx.recv_timeout(Duration::from_millis(100)) {
Ok(mut envelope) => { /* handle message */ }
Err(RecvTimeoutError::Timeout) => {
if cancellation_token.is_cancelled() { break; }
}
Err(RecvTimeoutError::Disconnected) => break,
}
This causes:
- Up to 100ms shutdown latency after
stop()is called - 10 wakeups/sec per idle actor (constant CPU churn)
- Unnecessary overhead for applications with many idle actors
Proposed fix
Replace the timeout-based polling with a poison-pill approach:
- Wrap mailbox messages:
enum MailboxItem<A> { Message(Box<dyn Envelope<A>>), Shutdown } - When
stop()is called, sendMailboxItem::Shutdownthrough the channel - Replace
recv_timeoutwith blockingrx.recv() - On
Shutdown, break the loop — instant cancellation, zero polling
This keeps CancellationToken for timers/streams but removes the polling loop from the core message path.
Files to change
concurrency/src/threads/actor.rs— message loop,stop()impl- Possibly
rt/src/threads/mod.rs— if channel type changes
Testing
- Existing thread actor tests should pass unchanged
- Add test verifying shutdown latency < 10ms
- Add test verifying idle actor has no CPU wakeups
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in concurrency/src/threads/actor.rs by tracing the message loop and stop() implementation, then check rt/src/threads/mod.rs if the channel type crosses that boundary. Review the existing thread actor tests before changing the mailbox flow. Done means shutdown no longer relies on recv_timeout polling, and the existing tests plus latency and idle-actor wakeup tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- distributed-systems
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100