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

Add benchmark and fast path for BufReader::read_exact #80201

Merged
merged 1 commit into from
Jan 17, 2021

Conversation

saethlin
Copy link
Member

At work, we have a wrapper type that implements this optimization. It would be nice if the standard library were faster.

Before:

test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       7,670 ns/iter (+/- 45)

After:

test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       4,457 ns/iter (+/- 41)

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 19, 2020
@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 15, 2021
@Dylan-DPC-zz
Copy link

r? @KodrAus

Copy link
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @saethlin! I just had one comment.

return Ok(());
}

while !buf.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to introduce a read_exact function with this default implementation and call it here and in Read::read_exact so that it’s clear this is our fallback.

@KodrAus
Copy link
Contributor

KodrAus commented Jan 16, 2021

Thanks @saethlin! Sorry, it looks like the convention here would be to call the function default_read_exact and put it up somewhere near the default_read_vectored function.

That’s just a tiny nit though. This looks good to me.

@KodrAus
Copy link
Contributor

KodrAus commented Jan 16, 2021

Once you’re ready would you be able to squash the commits down and we can merge it in?

@saethlin
Copy link
Member Author

Oh no I think I did this wrong 🤦

@saethlin
Copy link
Member Author

I tried to rebase then squash away my commits. Maybe that was the wrong thing to do, since GitHub thinks this is now 30 commits?

I really have no expertise in this, since at work we squash+merge all PRs. If I did something wrong please assist?

@KodrAus
Copy link
Contributor

KodrAus commented Jan 17, 2021

No problem! Git trips me up all the time. I hope you don't mind I force pushed your branch to fix it all up. I ended going with the nuclear option in git and cherry pick your commit back onto a clean master branch:

git checkout master
git cherry-pick 861edce52e4e118265d9fa366777546012829798

I then pushed that to your bufreader-read-exact branch and everything is looking good.

@KodrAus
Copy link
Contributor

KodrAus commented Jan 17, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jan 17, 2021

📌 Commit 4e27ed3 has been approved by KodrAus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2021
@saethlin
Copy link
Member Author

Thanks for fixing the commit history, I really appreciate it.

m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 17, 2021
…drAus

Add benchmark and fast path for BufReader::read_exact

At work, we have a wrapper type that implements this optimization. It would be nice if the standard library were faster.

Before:
```
test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       7,670 ns/iter (+/- 45)
```
After:
```
test io::buffered::tests::bench_buffered_reader_small_reads       ... bench:       4,457 ns/iter (+/- 41)
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2021
Rollup of 13 pull requests

Successful merges:

 - rust-lang#79298 (correctly deal with late-bound lifetimes in anon consts)
 - rust-lang#80031 (resolve: Reject ambiguity built-in attr vs different built-in attr)
 - rust-lang#80201 (Add benchmark and fast path for BufReader::read_exact)
 - rust-lang#80635 (Improve diagnostics when closure doesn't meet trait bound)
 - rust-lang#80765 (resolve: Simplify collection of traits in scope)
 - rust-lang#80932 (Allow downloading LLVM on Windows and MacOS)
 - rust-lang#80983 (Remove is_dllimport_foreign_item definition from cg_ssa)
 - rust-lang#81064 (Support non-stage0 check)
 - rust-lang#81080 (Force vec![] to expression position only)
 - rust-lang#81082 (BTreeMap: clean up a few more comments)
 - rust-lang#81084 (Use Option::map instead of open-coding it)
 - rust-lang#81095 (Use Option::unwrap_or instead of open-coding it)
 - rust-lang#81107 (Add NonZeroUn::is_power_of_two)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 152f425 into rust-lang:master Jan 17, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 17, 2021
@saethlin saethlin deleted the bufreader-read-exact branch February 5, 2021 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants