Skip to content

Commit

Permalink
Merge pull request #142 from ClickHouse/feat/zstd-reduce-memory-consu…
Browse files Browse the repository at this point in the history
…mption

feat(compress): reduce ZSTD encoder memory consumption
  • Loading branch information
ernado authored Jun 27, 2022
2 parents 92362cb + 0647f4d commit 3b0bd0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/compress/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func (r *Reader) readBlock() error {
if r.zstd == nil {
// Lazily initializing to prevent spawning goroutines in NewReader.
// See https://github.com/golang/go/issues/47056#issuecomment-997436820
zstdReader, err := zstd.NewReader(nil, zstd.WithDecoderConcurrency(1))
zstdReader, err := zstd.NewReader(nil,
zstd.WithDecoderConcurrency(1),
zstd.WithDecoderLowmem(true),
)
if err != nil {
return errors.Wrap(err, "zstd")
}
Expand Down
10 changes: 9 additions & 1 deletion internal/compress/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ func (w *Writer) Compress(m Method, buf []byte) error {
}

func NewWriter() *Writer {
w, err := zstd.NewWriter(nil,
zstd.WithEncoderLevel(zstd.SpeedDefault),
zstd.WithEncoderConcurrency(1),
zstd.WithLowerEncoderMem(true),
)
if err != nil {
panic(err)
}
return &Writer{
lz4: &lz4.Compressor{},
zstd: &zstd.Encoder{},
zstd: w,
}
}

0 comments on commit 3b0bd0d

Please sign in to comment.