Uh oh!
There was an error while loading. Please reload this page.
Let io::copy reuse BufWriter buffers - #78641
Conversation
rust-highfive
commented
Nov 1, 2020
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
Uh oh!
There was an error while loading. Please reload this page.
bors
commented
Nov 14, 2020
☔ The latest upstream changes (presumably #75272) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
This comment has been minimized.
This comment has been minimized.
the8472
commented
Nov 18, 2020
The resulting code feels a bit gnarly but I didn't want to duplicate the read-write loop because it contains all that unsafe code around uninitialized memory. If it's accaptable to duplicate that code then the generic and the BufWriter-specific version could individually be made cleaner. |
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
the8472
commented
Dec 12, 2020
I'll hold off fixing the nits until I get a higher-level review. |
This comment has been minimized.
This comment has been minimized.
shepmaster
commented
Jan 1, 2021
I'ven't been able to give this the time it deserves. r? @sfackler |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
It seems strange for there to be specialization in the function used "when specializations are not available or not applicable".
There was a problem hiding this comment.
That refers to another set of specializations. I'll try to reword it.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sfackler
commented
Feb 1, 2021
This looks good, thanks! @bors r+ |
bors
commented
Feb 1, 2021
📌 Commit 4105506 has been approved by |
| // Safety: The initializer contract guarantees that either it or `read` | ||
| // will have initialized these bytes. And we just checked that the number | ||
| // of bytes is within the buffer capacity. | ||
| unsafe { buf.set_len(buf.len() + bytes_read) }; |
There was a problem hiding this comment.
Huh, is std being built with polonious?
There was a problem hiding this comment.
Not sure what is causing surprise here. The x.foo(x.bar())? Isn't that just two-phase borrows?
bors
commented
Feb 1, 2021
⌛ Testing commit 4105506 with merge 8bd506e0f39d10dcc588ae469c9c6c73d0c568c6... |
bors
commented
Feb 1, 2021
💥 Test timed out |
bjorn3
commented
Feb 1, 2021
The macOS builder is still running and showing new logs. |
rust-log-analyzer
commented
Feb 1, 2021
bjorn3
commented
Feb 1, 2021
@bors r+ retry |
bors
commented
Feb 1, 2021
💡 This pull request was already approved, no need to approve it again.
|
bors
commented
Feb 1, 2021
📌 Commit 4105506 has been approved by |
bjorn3
commented
Feb 1, 2021
Oops, should have done @bors r=sfackler |
bors
commented
Feb 1, 2021
💡 This pull request was already approved, no need to approve it again.
|
bors
commented
Feb 1, 2021
📌 Commit 4105506 has been approved by |
Let io::copy reuse BufWriter buffers This optimization will allow users to implicitly set the buffer size for io::copy by wrapping the writer into a `BufWriter` if the default block size is insufficient, which should fixrust-lang#49921 Due to min_specialization limitations this approach only works with `BufWriter` but not for `BufReader<R>` since `R` is unconstrained and thus the necessary specialization on `R: Read` is not always applicable. Once specialization becomes more powerful this optimization could be extended to look at the reader and writer side and use whichever buffer is larger.
…as-schievink Rollup of 12 pull requests Successful merges: - rust-lang#78641 (Let io::copy reuse BufWriter buffers) - rust-lang#79291 (Add error message for private fn) - rust-lang#81364 (Improve `rustc_mir_build::matches` docs) - rust-lang#81387 (Move some tests to more reasonable directories - 3) - rust-lang#81463 (Rename NLL* to Nll* accordingly to C-CASE) - rust-lang#81504 (Suggest accessing field when appropriate) - rust-lang#81529 (Fix invalid camel case suggestion involving unicode idents) - rust-lang#81536 (Indicate both start and end of pass RSS in time-passes output) - rust-lang#81592 (Rustdoc UI fixes) - rust-lang#81594 (Avoid building LLVM just for llvm-dwp) - rust-lang#81598 (Fix calling convention for CRT startup) - rust-lang#81618 (Sync rustc_codegen_cranelift) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
| writer.flush_buf()?; |
There was a problem hiding this comment.
I think putting this in an else branch will be clearer, if the previous conditions are hit all will either continue or return, it does not reach this part.
This optimization will allow users to implicitly set the buffer size for io::copy by wrapping the writer into a
BufWriterif the default block size is insufficient, which should fix#49921Due to min_specialization limitations this approach only works with
BufWriterbut not forBufReader<R>sinceRis unconstrained and thus the necessary specialization onR: Readis not always applicable. Once specialization becomes more powerful this optimization could be extended to look at the reader and writer side and use whichever buffer is larger.