diff --git a/CHANGELOG.md b/CHANGELOG.md index fb101c321..bb2d871b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Changelog for NeoFS Node ### Removed ### Updated - `neo-go` to `v0.100.1` +- `github.com/klauspost/compress` to `v1.15.13` ### Updating from v0.35.0 diff --git a/go.mod b/go.mod index 41bc5548d..9ad0843db 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/google/go-github/v39 v39.2.0 github.com/google/uuid v1.3.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/klauspost/compress v1.15.9 + github.com/klauspost/compress v1.15.13 github.com/mitchellh/go-homedir v1.1.0 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multiaddr v0.4.0 diff --git a/go.sum b/go.sum index 2837e39d3..5487b0e87 100644 --- a/go.sum +++ b/go.sum @@ -499,8 +499,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= -github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= +github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0= +github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= diff --git a/pkg/local_object_storage/blobstor/compression/bench_test.go b/pkg/local_object_storage/blobstor/compression/bench_test.go new file mode 100644 index 000000000..6e05366cf --- /dev/null +++ b/pkg/local_object_storage/blobstor/compression/bench_test.go @@ -0,0 +1,49 @@ +package compression + +import ( + "crypto/rand" + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func BenchmarkCompression(b *testing.B) { + c := Config{Enabled: true} + require.NoError(b, c.Init()) + + for _, size := range []int{128, 1024, 32 * 1024, 32 * 1024 * 1024} { + b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) { + b.Run("zeroed slice", func(b *testing.B) { + data := make([]byte, size) + benchWith(b, c, data) + }) + b.Run("not so random slice (block = 123)", func(b *testing.B) { + data := notSoRandomSlice(size, 123) + benchWith(b, c, data) + }) + b.Run("random slice", func(b *testing.B) { + data := make([]byte, size) + rand.Read(data) + benchWith(b, c, data) + }) + }) + } +} + +func benchWith(b *testing.B, c Config, data []byte) { + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _ = c.Compress(data) + } +} + +func notSoRandomSlice(size, blockSize int) []byte { + data := make([]byte, size) + rand.Read(data[:blockSize]) + for i := blockSize; i < size; i += blockSize { + copy(data[i:], data[:blockSize]) + } + return data +} diff --git a/pkg/local_object_storage/blobstor/compression/compress.go b/pkg/local_object_storage/blobstor/compression/compress.go index 44b83d416..6cab3c29c 100644 --- a/pkg/local_object_storage/blobstor/compression/compress.go +++ b/pkg/local_object_storage/blobstor/compression/compress.go @@ -86,7 +86,8 @@ func (c *Config) Compress(data []byte) []byte { if c == nil || !c.Enabled { return data } - return c.encoder.EncodeAll(data, make([]byte, 0, len(data))) + maxSize := c.encoder.MaxEncodedSize(len(data)) + return c.encoder.EncodeAll(data, make([]byte, 0, maxSize)) } // Close closes encoder and decoder, returns any error occurred.