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
io: make NopCloser forward WriterTo calls to underlying reader #51566
Comments
It's hard to argue with the performance win here. |
This proposal has been added to the active column of the proposals project |
It seems like we should make this change, which would mean two different possible underlying types for the interface returned by NopCloser. And then later we can decide whether to make io.Copy support ErrUnsupported, which would get us back to one underlying type. |
I completely agree that this is a good idea. Because we would still do the |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Seems that approved proposal is getting nowhere. Use and io/fs/os |
@andig My current understanding is that we will implement this using reflection in |
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
Change https://go.dev/cl/400236 mentions this issue: |
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
This patch also include related fixes to net/http's NopCloser unwrapping logic. The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. NopCloser didn't even had direct tests before. Fixes golang#51566
The io_test.go don't bother to test actually reading or WritingTo of the NopCloser because the logic is simple. It didn't even had direct tests before. Fixes golang#51566
Because I belive that is clearer with code than words:
Replace:
With something like this:
That allows an about ~1.5X faster read time when wrapping
bytes.NewReader
orbytes.Buffer
inio.NopCloser
(actually it turns it into a constant time operation, whereio.Reader
has a linear time):As you can see this is a surprisingly popular patern: https://github.com/golang/go/search?q=NopCloser+bytes.NewReader
The only issue I see with this, is that pure
io.Reader
are now ~1.5x time slower toNopCloser
-ify. (that the cost of trying the cast that would fail). Since mostNopCloser
are created with a known type, I would hope thatNopCloser
gets inlined and the type cast is solved at compile time, but it seems that not happening.The text was updated successfully, but these errors were encountered: