Skip to content

Reduce memory allocations in Reader#20

Merged
Viq111 merged 3 commits intoDataDog:1.xfrom
juicedata:reader
Mar 13, 2018
Merged

Reduce memory allocations in Reader#20
Viq111 merged 3 commits intoDataDog:1.xfrom
juicedata:reader

Conversation

@davies
Copy link
Contributor

@davies davies commented Nov 6, 2017

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.

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)

Choose a reason for hiding this comment

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

— 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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, will change that to 0.

@yasushi-saito
Copy link

Can we get this change in?

Copy link
Collaborator

@Viq111 Viq111 left a comment

Choose a reason for hiding this comment

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

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

@Viq111 Viq111 merged commit 871f24a into DataDog:1.x Mar 13, 2018
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.

4 participants