diff --git a/unified-scheduler-pool/src/lib.rs b/unified-scheduler-pool/src/lib.rs index 45c1d45e59685a..f28c6ca49d6291 100644 --- a/unified-scheduler-pool/src/lib.rs +++ b/unified-scheduler-pool/src/lib.rs @@ -245,47 +245,22 @@ type ExecutedTaskPayload = SubchanneledPayload, ()>; // this switching can happen exactly once for each thread. // // Overall, this greatly simplifies the code, reduces CAS/syscall overhead per messaging to the -// minimum at the cost of a single heap allocation per switching for the sake of Box-ing the Self -// type to avoid infinite mem::size_of() due to the recursive type structure. Needless to say, such -// an allocation can be amortized to be negligible. +// minimum at the cost of a single channel recreation per switching. Needless to say, such an +// allocation can be amortized to be negligible. mod chained_channel { use super::*; // hide variants by putting this inside newtype enum ChainedChannelPrivate { Payload(P), - ContextAndChannel(Box>), + ContextAndChannel(C, Receiver>), } pub(super) struct ChainedChannel(ChainedChannelPrivate); - trait WithContextAndPayload: Send + Sync { - fn context_and_channel(self: Box) -> ContextAndChannelInner; - } - - type ContextAndChannelInner = (C, Receiver>); - - struct ContextAndChannelWrapper(ContextAndChannelInner); - - impl WithContextAndPayload for ContextAndChannelWrapper - where - P: Send + Sync, - C: Send + Sync, - { - fn context_and_channel(self: Box) -> ContextAndChannelInner { - self.0 - } - } - - impl ChainedChannel - where - P: Send + Sync + 'static, - C: Send + Sync + 'static, - { + impl ChainedChannel { fn chain_to_new_channel(context: C, receiver: Receiver) -> Self { - Self(ChainedChannelPrivate::ContextAndChannel(Box::new( - ContextAndChannelWrapper((context, receiver)), - ))) + Self(ChainedChannelPrivate::ContextAndChannel(context, receiver)) } } @@ -293,11 +268,7 @@ mod chained_channel { sender: Sender>, } - impl ChainedChannelSender - where - P: Send + Sync + 'static, - C: Send + Sync + 'static + Clone, - { + impl ChainedChannelSender { fn new(sender: Sender>) -> Self { Self { sender } } @@ -355,21 +326,18 @@ mod chained_channel { pub(super) fn after_select(&mut self, message: ChainedChannel) -> Option

{ match message.0 { ChainedChannelPrivate::Payload(payload) => Some(payload), - ChainedChannelPrivate::ContextAndChannel(new_context_and_channel) => { - (self.context, self.receiver) = new_context_and_channel.context_and_channel(); + ChainedChannelPrivate::ContextAndChannel(context, channel) => { + self.context = context; + self.receiver = channel; None } } } } - pub(super) fn unbounded( + pub(super) fn unbounded( initial_context: C, - ) -> (ChainedChannelSender, ChainedChannelReceiver) - where - P: Send + Sync + 'static, - C: Send + Sync + 'static + Clone, - { + ) -> (ChainedChannelSender, ChainedChannelReceiver) { let (sender, receiver) = crossbeam_channel::unbounded(); ( ChainedChannelSender::new(sender),