Summary
The SchedulerState in src/client/pool/scheduler.rs currently uses three separate collections keyed by handle ID:
waiters: HashMap<u64, WaiterSender<…>>
fifo_waiters: VecDeque<u64>
round_robin_handles: VecDeque<u64>
This design requires keeping all three structures consistent and involves repeated retain scans in the round-robin and deregister paths, which adds maintenance burden and cross-collection consistency concerns.
Proposed improvement
Restructure SchedulerState to use per-handle waiter queues for round-robin and a single anonymous FIFO queue for FIFO policy. This would:
- Eliminate the global
waiters map and the fifo_waiters ID queue.
- Remove
retain scans from take_next_round_robin_waiter and deregister_handle.
- Simplify the
take_next_* selection logic by popping directly from per-handle queues.
- Eliminate cross-collection consistency concerns entirely.
All existing behaviour would be preserved: FIFO policy retains strict arrival-order servicing, and round-robin policy continues to rotate fairly among registered handles.
Context
This was flagged as an architectural suggestion during the review of PR #498 (#498). The current implementation is correct and all tests pass; this is a follow-up refactoring opportunity to reduce complexity and improve maintainability.
Requested by @leynos.
Summary
The
SchedulerStateinsrc/client/pool/scheduler.rscurrently uses three separate collections keyed by handle ID:waiters: HashMap<u64, WaiterSender<…>>fifo_waiters: VecDeque<u64>round_robin_handles: VecDeque<u64>This design requires keeping all three structures consistent and involves repeated
retainscans in the round-robin and deregister paths, which adds maintenance burden and cross-collection consistency concerns.Proposed improvement
Restructure
SchedulerStateto use per-handle waiter queues for round-robin and a single anonymous FIFO queue for FIFO policy. This would:waitersmap and thefifo_waitersID queue.retainscans fromtake_next_round_robin_waiterandderegister_handle.take_next_*selection logic by popping directly from per-handle queues.All existing behaviour would be preserved: FIFO policy retains strict arrival-order servicing, and round-robin policy continues to rotate fairly among registered handles.
Context
This was flagged as an architectural suggestion during the review of PR #498 (#498). The current implementation is correct and all tests pass; this is a follow-up refactoring opportunity to reduce complexity and improve maintainability.
Requested by @leynos.