Skip to content
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

Merged
merged 6 commits into from
Nov 2, 2023
Merged

feat: no-buffer split #126

merged 6 commits into from
Nov 2, 2023

Conversation

fortuna
Copy link
Contributor

@fortuna fortuna commented Oct 31, 2023

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.

@fortuna fortuna requested a review from jyyi1 October 31, 2023 00:07
Copy link
Contributor Author

@fortuna fortuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts?

Copy link
Contributor

@jyyi1 jyyi1 left a 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/reader_test.go Outdated Show resolved Hide resolved
transport/split/reader_test.go Outdated Show resolved Hide resolved
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})
Copy link
Contributor

@jyyi1 jyyi1 Nov 2, 2023

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.

Suggested change
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)

Copy link
Contributor Author

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.

@fortuna fortuna merged commit 242ca55 into main Nov 2, 2023
6 checks passed
@fortuna fortuna deleted the fortuna-split branch November 2, 2023 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants