diff --git a/table/table.go b/table/table.go index 25227be34..db79765c2 100644 --- a/table/table.go +++ b/table/table.go @@ -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 @@ -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") }