Skip to content

Commit

Permalink
Fix SplitSink performance problem caused by flushing inner sink every…
Browse files Browse the repository at this point in the history
… time
  • Loading branch information
doyoubi authored and cramertj committed Nov 13, 2019
1 parent f3d262e commit 5b63dfd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion futures-util/src/stream/stream/split.rs
Expand Up @@ -61,6 +61,19 @@ impl<S: Sink<Item> + Unpin, Item> SplitSink<S, Item> {
}
}

impl<S: Sink<Item>, Item> SplitSink<S, Item> {
fn poll_flush_slot(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), S::Error>> {
let this = &mut *self;
let mut inner = ready!(this.lock.poll_lock(cx));
if this.slot.is_some() {
ready!(inner.as_pin_mut().poll_ready(cx))?;
Poll::Ready(inner.as_pin_mut().start_send(this.slot.take().unwrap()))
} else {
Poll::Ready(Ok(()))
}
}
}

impl<S: Sink<Item>, Item> Sink<Item> for SplitSink<S, Item> {
type Error = S::Error;

Expand All @@ -69,7 +82,7 @@ impl<S: Sink<Item>, Item> Sink<Item> for SplitSink<S, Item> {
if self.slot.is_none() {
return Poll::Ready(Ok(()));
}
ready!(self.as_mut().poll_flush(cx))?;
ready!(self.as_mut().poll_flush_slot(cx))?;
}
}

Expand Down

0 comments on commit 5b63dfd

Please sign in to comment.