From 5eb05a0afe9e32baad77e6ff4ea24ef7adb4c7bc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 20 Apr 2022 20:46:11 +0200 Subject: [PATCH] Configure zstd encoder/decoder --- internal/repository/repository.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 8ca39d50b..ece395f3a 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -329,7 +329,18 @@ func (r *Repository) getZstdEncoder() *zstd.Encoder { level = zstd.SpeedBestCompression } - enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(level)) + opts := []zstd.EOption{ + // Set the compression level configured. + zstd.WithEncoderLevel(level), + // Disable CRC, we have enough checks in place, makes the + // compressed data four bytes shorter. + zstd.WithEncoderCRC(false), + // Set a window of 512kbyte, so we have good lookbehind for usual + // blob sizes. + zstd.WithWindowSize(512 * 1024), + } + + enc, err := zstd.NewWriter(nil, opts...) if err != nil { panic(err) } @@ -340,7 +351,15 @@ func (r *Repository) getZstdEncoder() *zstd.Encoder { func (r *Repository) getZstdDecoder() *zstd.Decoder { r.allocDec.Do(func() { - dec, err := zstd.NewReader(nil) + opts := []zstd.DOption{ + // Use all available cores. + zstd.WithDecoderConcurrency(0), + // Limit the maximum decompressed memory. Set to a very high, + // conservative value. + zstd.WithDecoderMaxMemory(16 * 1024 * 1024 * 1024), + } + + dec, err := zstd.NewReader(nil, opts...) if err != nil { panic(err) }