-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In ready_chunks, reserve capacity based on size_hint #2661
base: master
Are you sure you want to change the base?
Conversation
Reserving `ready_chunks` limit every time may be too expensive when the limit is high but only a few number of messages available. Now rely on `Stream::size_hint` to reserve the capacity. If underlying stream implements `size_hint`, this will work great. Otherwise `ready_chunk` will be somewhat less efficient. This is better alternative to rust-lang#2657
8ed5677
to
19338ee
Compare
Do you have any benchmarks pr use cases that demonstrate an improvement in performance? |
I can create a benchmark which demonstrates the behavior:
Current behavior of excessive memory allocation prevents using |
// Note we reserve capacity here, not when `items` is created, | ||
// because stream may know the remaining size, | ||
// but items might not be readily available. | ||
let size_hint = this.stream.as_mut().size_hint().0.wrapping_add(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this wrapping_add instead of saturating_add?
Thanks for the PR! That said, this seems to be somewhat more reasonable than #2657 or the current implementation. I tend to merge this once the review is addressed. |
Is there a plan to merge this? |
How to reuse it? poll_next returns an owned Vec. |
Can't we return a reference to the internal vector? |
I don't think it is possible without using GAT in the Future trait. |
Its worth trying to support this. |
Reserving
ready_chunks
limit every time may be too expensive when the limit is high but only a few number of messages available.Now rely on
Stream::size_hint
to reserve the capacity. If underlying stream implementssize_hint
, this will work great. Otherwiseready_chunk
will be somewhat less efficient.This is better alternative to #2657