Reduce memory allocations in Reader#20
Merged
Viq111 merged 3 commits intoDataDog:1.xfrom Mar 13, 2018
Merged
Conversation
jimsmart
reviewed
Jan 15, 2018
zstd_stream.go
Outdated
| if err == io.EOF && r.compressionLeft == 0 { | ||
| return got, io.EOF | ||
| } else if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { | ||
| return got, fmt.Errorf("failed to read from underlying reader: %s", err) |
There was a problem hiding this comment.
— Is it correct that 'got' is returned here instead of 0? Is this a typo, or is this intentional?
In Go, it is idiomatic to return the zero value with a non-nil error (except when dealing with EOF).
Much cleaner handling of buffers though, good work! — it should give a small performance boost also 👍
Contributor
Author
There was a problem hiding this comment.
Good call, will change that to 0.
|
Can we get this change in? |
Viq111
approved these changes
Mar 13, 2018
Collaborator
Viq111
left a comment
There was a problem hiding this comment.
lgtm!
Thanks for the contribution and sorry for the delay.
I tested it locally against mr and looks good:
# Before
ᐅ go test -v -bench BenchmarkStreamDecompression -benchtime 30s
goos: darwin
goarch: amd64
BenchmarkStreamDecompression-4 2000 31254220 ns/op 319.01 MB/s
PASS
# After
ᐅ go test -v -bench BenchmarkStreamDecompression -benchtime 30s
goos: darwin
goarch: amd64
BenchmarkStreamDecompression-4 2000 24829416 ns/op 401.56 MB/s
PASS
ok
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.
The reader has both decompressionBuffer and dstBuffer for buffering, seems that dstBuffer is duplicated, having decompressionBuffer should be enough.
Also, srcBuffer is not necessary.
We could reduced the memory allocation for them, also avoid the memory copying.