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

Reuse buffer for decompression #1247

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ type Options struct {
ZSTDCompressionLevel int
}

var slicePool = sync.Pool{
New: func() interface{} {
b := make([]byte, 5<<10)
return &b
},
}

// TableInterface is useful for testing.
type TableInterface interface {
Smallest() []byte
Expand Down Expand Up @@ -619,13 +626,18 @@ func NewFilename(id uint64, dir string) string {

// decompressData decompresses the given data.
func (t *Table) decompressData(data []byte) ([]byte, error) {
buf := slicePool.Get().(*[]byte)
*buf = (*buf)[:0]

switch t.opt.Compression {
case options.None:
return data, nil
case options.Snappy:
return snappy.Decode(nil, data)
slicePool.Put(&data)
return snappy.Decode(*buf, data)
case options.ZSTD:
return y.ZSTDDecompress(nil, data)
slicePool.Put(&data)
return y.ZSTDDecompress(*buf, data)
}
return nil, errors.New("Unsupported compression type")
}