Closed stepancheg closed 1 year ago
Hmm... Depending on the size of the item, reallocation may occur with each push, but 1024 bytes on the stack is relatively large, so it probably seems fine?
reallocation may occur with each push,
Snippet you pointed at is min non-zero capacity. The following line is:
let cap = cmp::max(min_non_zero_cap, cap);
where old cap
is double of previous capacity. So it will be amortized constant per push. So for 8 bytes objects for example, reallocation will happen at sizes: 4, 8, 16, 32, ...
Or I didn't understand your comment.
Closing in favor of https://github.com/rust-lang/futures-rs/pull/2661.
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).