Move std::io::copy to alloc::io - #158548
Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rustbot blocked |
This comment has been minimized.
This comment has been minimized.
1bcdfe1 to
43f67ba
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
90ec159 to
8139972
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8139972 to
cb62676
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cb62676 to
3bb0364
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3bb0364 to
df9a018
Compare
This comment has been minimized.
This comment has been minimized.
df9a018 to
8f363d9
Compare
This comment has been minimized.
This comment has been minimized.
8f363d9 to
d331e98
Compare
|
@rustbot label -T-compiler -T-rustdoc -T-rustdoc-frontend |
72de226 to
b2a9ee4
Compare
This comment has been minimized.
This comment has been minimized.
| SpecCopyInner::copy((reader, writer)) | ||
| } | ||
|
|
||
| trait SpecCopyInner { |
There was a problem hiding this comment.
Is there a reason why this has to go through a layer of indirection via specialized_copy instead of just being used directly?
There was a problem hiding this comment.
Yeah we can't directly call SpecCopy::copy since that would require a default blanket implementation of SpecCopy for all Read types, which doesn't work without another intermediate type for marking that specialization too. I also prefer to have a simple function like specialized_copy exported instead of SpecCopyInner::copy, since that trait purely exists as a specialization hack.
There was a problem hiding this comment.
Right, I guess what I meant was whether specialized_copy should exist instead of just calling SpecCopyInner::copy.
|
Left some comments as I try to wrap my brain around how these things work. Also going to want a perf run on the final versions since my guess is that these are going to be high-impact due to cross-crate inlining changes, but, we'll see if that's moot like it was for previous runs. |
Rely on specialization to allow `std` to provide optimized copy implementations.
b2a9ee4 to
ab7f8ad
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
ab7f8ad to
174d318
Compare
I'm hopeful there wont be any performance loss with this move, but this is definitely the one move I would expect it to happen with, since specialization is very not ready for general use. I'm not even sure if cross-crate specialization is currently used at all. So yes please on a perf run! |
|
(Mostly just wanted to clarify I was going to wait until the doc/etc. comments are fixed before running perf, but yes, we'll be doing that.) |
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
174d318 to
a0ff5e6
Compare
View all comments
ACP: rust-lang/libs-team#755
Tracking issue: #154046
Split From: #156527
Blocked On: #158547Description
Moves
std::io::copyintoalloc::io. Blocked on #158547.This relies on specialization to allow
stdto provide optimised copy implementations for its types where appropriate. The exact technique involves defining a new trait,alloc::io::SpecCopy:Since optimised copying requires both the reader and writer to support the operation between each other, we can choose one of them to be the implementer of the copy algorithm, and delegate specialization to it. In this case, I've chosen the reader to be the provider of the specialized copy implementation arbitrarily. Note that the
SpecCopy::copyfunction is generic over the reader specifically to allow wrappers likeTake<R>to be visible to the implementation ofcopy.Because this introduces a new layer of specialization to
io::copy, I think this PR should be benchmarked to make sure performance characteristics aren't too different. I am expecting compilation time to be slightly worse, since there's just more specialization happening, but the actual code run should be the same.Notes
alloc::ioandcore::io#154046 (comment) for a review order and broader context for this PR.