feat(bindings/go): add ReaderFrom and WriterTo support - #8258
Open
ClSlaid wants to merge 4 commits into
Open
Conversation
ClSlaid
marked this pull request as ready for review
September 8, 2026 09:08
Xuanwo
requested changes
Sep 8, 2026
Member
There was a problem hiding this comment.
didn't feel good to place them in a new file called stream.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #8248.
Rationale for this change
The default
io.Copyloop uses a 32 KiB buffer. Small writes repeat the Go-to-native call and the native data allocation.What changes are included in this PR?
Writer.ReadFromandReader.WriteTo. Each method uses one reusable 256 KiB buffer.io.CopyBufferto handle byte counts, EOF, and write errors.Are there any user-facing changes?
io.Copycan select the new methods. Whenio.CopyBufferselects either method, that method uses its own buffer.The copy methods leave both streams open. The caller must call
Writer.Closeto complete the write and get its metadata.Validation
go vet, and golangci-lint v2.12.2 passed.A local benchmark copied a 16 MiB file 100 times on macOS arm64 (Apple M4, Go 1.27.1). Copy time includes stream creation and Close.
b6cf44f7)The larger buffer reduces call counts but increases allocated bytes and the delay before the first write. Go allocation metrics exclude Rust allocations.
AI Usage Statement
AI assisted the implementation, tests, performance analysis, and documentation. Network service throughput, multipart latency, and concurrent transfer memory use remain unmeasured.