-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: no-buffer split #126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is good, with some minor suggestions. Thanks.
transport/split/writer.go
Outdated
n, err := io.Copy(w.writer, source) | ||
written += n | ||
func (w *splitWriterReaderFrom) ReadFrom(source io.Reader) (int64, error) { | ||
written, err := w.ReaderFrom.ReadFrom(&splitReader{source, w.prefixBytes}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative way is to reuse io
's standard readers. I'm ok with both, you can choose whichever one you prefer.
written, err := w.ReaderFrom.ReadFrom(&splitReader{source, w.prefixBytes}) | |
limit := io.LimitReader(source, w.prefixBytes) | |
split := io.MultiReader(limit, source) | |
written, err := w.ReaderFrom.ReadFrom(split) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Less code to maintain.
Co-authored-by: J. Yi <[email protected]>
The ReadFrom call no longer needs to allocate a buffer now. The buffer is provided by the inner ReaderFrom.
We should prefer ReadFrom when possible to avoid unnecessary buffers, but it needs to be properly implemented. This is an example of how we can accomplish that.