-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Speed up read_to_end helper function using buffer capacity for read size #35844
Speed up read_to_end helper function using buffer capacity for read size #35844
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The buffer's capacity or 16 bytes, whichever is larger, is the minimum start read size, but it will get twice as large with each read.
7fb930e
to
a21c7b5
Compare
Thanks for the PR! This is a slightly different fix than what I had in mind, though. I think that calling In the specific case of |
@alexcrichton The comment just above that line says that calling |
Bah, right! I believe though we could implement I'm somewhat hesitant to change the behavior of |
With my changes, these are the results for a file with 20971520 bytes. The alloc variant calls
With the old code:
|
@Mark-Simulacrum if I'm reading that right, it looks like the changes here are 2x slower? |
Nearly 3x; but yes. I'm thinking we should close since I can't see a clear path forward; though I'd be happy to try and implement something different if it's suggested. Perhaps the idea of special casing File and a few other structs' Read::read_to_string methods is worth looking into. |
Ok, sounds good to me. And yeah if you want to explore that route seems good to me! |
The buffer's capacity or 16 bytes, whichever is larger, is the minimum start read size, but it will get twice as large with each read.
Fixes #35823.