Skip to content
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

Consider adding size_hint to Stream #170

Closed
carllerche opened this issue Sep 21, 2016 · 4 comments · Fixed by #1853
Closed

Consider adding size_hint to Stream #170

carllerche opened this issue Sep 21, 2016 · 4 comments · Fixed by #1853

Comments

@carllerche
Copy link
Member

This would be helpful for Stream::collect

Also, I often create empty streams to represent no body when working w/ HTTP, it would be nice to just skip all the work if the body is empty.

@alexcrichton
Copy link
Member

I can see how Stream::collect could use this to prevent excessive allocations, but I'm not quite sure how that connects to the bodies you mentioned next?

I feel like this is a great optimization opportunity for iterators, but not necessarily streams. Would be good to have some examples in practice that this helps to evaluate as well!

@carllerche
Copy link
Member Author

For example, if I know that the HTTP body is empty (size hint would be 0), then I could terminate the HTTP/2 stream right after the head and not need to write an empty body stream frame.

@khuey
Copy link
Contributor

khuey commented Feb 19, 2019

I also think this would be useful. I've written a bunch of code of the form

  1. Start with a data structure
  2. For each element in that data structure, do something asynchronously. The actual asynchronous operation here is usually performing an HTTP request and get the response. Generally the structure is converted into an iterator and then the iterator is fed to futures_ordered or futures_unordered depending on whether the initial data structure was a vector or a hash table.
  3. Collect all the results back into a data structure

@taiki-e
Copy link
Member

taiki-e commented Aug 29, 2019

We cannot optimize current StreamExt::collect with this, but it would be probably useful for some use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants