Skip to content

Commit

Permalink
Do not allocate capacity in ready_chunks
Browse files Browse the repository at this point in the history
`read_chunks` practically often returns items when not all capacity
filled.  So always allocating full capacity results in excessive
allocation.

This is especially an issue when `capacity` parameter passed is
large (to be able to handle streams efficiently under high load).
  • Loading branch information
stepancheg committed Oct 22, 2022
1 parent 8cfc085 commit d8b355a
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions futures-util/src/stream/stream/ready_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ impl<St: Stream> Stream for ReadyChunks<St> {
}

// Push the ready item into the buffer and check whether it is full.
// If so, replace our buffer with a new and empty one and return
// the full one.
// If so, return it.
Poll::Ready(Some(item)) => {
if items.is_empty() {
items.reserve(*this.cap);
}
items.push(item);
if items.len() >= *this.cap {
return Poll::Ready(Some(items));
Expand Down

0 comments on commit d8b355a

Please sign in to comment.