Skip to content

Commit

Permalink
Merge pull request #1869 from wyndhblb/asapp-static-zstd
Browse files Browse the repository at this point in the history
zstd: encode+decode performance improvements
  • Loading branch information
dnwe authored Apr 29, 2021
2 parents 0e2e2a4 + 76988ca commit 9a7d94e
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions zstd.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
package sarama

import (
"sync"

"github.com/klauspost/compress/zstd"
)

var (
zstdDec *zstd.Decoder
zstdEnc *zstd.Encoder

zstdEncOnce, zstdDecOnce sync.Once
)
var zstdDec, _ = zstd.NewReader(nil)
var zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true))

func zstdDecompress(dst, src []byte) ([]byte, error) {
zstdDecOnce.Do(func() {
zstdDec, _ = zstd.NewReader(nil)
})
return zstdDec.DecodeAll(src, dst)
}

func zstdCompress(dst, src []byte) ([]byte, error) {
zstdEncOnce.Do(func() {
zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true))
})
return zstdEnc.EncodeAll(src, dst), nil
}

0 comments on commit 9a7d94e

Please sign in to comment.