-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: x/exp/mmap: implement io.WriterTo and io.ReadSeeker #56422
Comments
Is there maybe still a mistake in the benchmark that might be skewing the results? |
CC @nigeltao |
Yeah, I'm OK with adding |
If you're talking about |
Absolutely, that's exactly what we're currently doing (plus some hacks to work around #16474). The problem with that is that we have multiple concurrent readers of large(-ish) files, in which case the overhead of multiple independent
I'm not sure that we must have a file position to implement
That reads to me like there is currently no way to move the the seek offset in This doesn't mean we couldn't implement it, but AFAICT these two are orthogonal. What am I missing? |
I don't think it's orthogonal. The In any case, I started a golang-nuts discussion: |
Separately, your benchmark code above uses |
oh boy, you're right, of course 😞
We can wait a bit for any counter-arguments, but yours and @ianlancetaylor's arguments make sense. I'll include it in the proposal. |
oh, wait, not so sure: |
See https://go.dev/play/p/LybHg59d4KU I'll repeat: how would it work otherwise? The |
🤦♂️ yes, of course, sorry for the noise. (feel free to mark the last couple of msgs as off-topic; they don't really contribute to the actual proposal discussion) |
OK, I'll repeat that, for the actual proposal, I'm OK with adding Still, if you're ultimately concerned about |
Change https://go.dev/cl/555796 mentions this issue: |
After a regretable long absence, I finally came back to this. Relatedly: #56480 made this relevant for |
wouldn't the see: #39683 |
@sbinet true, but then we'd need something self-referential like this: r := &ReaderAt{
data: data,
}
r.SectionReader = io.NewSectionReader(r, 0, size) and func (r *ReaderAt) WriteTo(w io.Writer) (int64, error) {
pos, err := r.Seek(0, io.SeekCurrent)
if err != nil {
return 0, fmt.Errorf("mmap: WriteTo: %w", err)
}
n, err := w.Write(r.data[pos:])
_, seekErr := r.Seek(int64(n), io.SeekCurrent)
if seekErr != nil {
return 0, fmt.Errorf("mmap: WriteTo: %w", err)
}
return int64(n), err
} That didn't feel quite clean and I felt "a bit of copying is better than a bit dependency" (but applying that to the stdlib itself may be a bit too much 😅) I'm totally ok going that way if that's preferred! |
I was just digging up the previous consensus about this issue :) |
@sbinet just changed the implementation to use PTAL |
A naive implementation of
io.WriterTo
inmmap.ReaderAt
seems to bring the following performance improvement when using code that relies onio.Copy
(e.g.http.ServeContent
).Benchmark code
This proposal would probably also solve #20642, as suggested.
Update 2022-10-27: since repeated uses of
WriteTo()
should behave like other readers (i.e.: keep state to avoid re-writing the wholemmap.ReaderAt
), this proposal also implies an implementation ofio.ReadSeeker
.The text was updated successfully, but these errors were encountered: