From 9761b7f3efaf4234606d5f0186617cf5fa3eb537 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 16 Oct 2021 18:20:01 +0300 Subject: [PATCH] vendor: update github.com/valyala/gozstd from v1.13.0 to v1.14.1 This should reduce memory usage in vmagent when compressing large scrape responses in stream parsing mode --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/valyala/gozstd/gozstd.go | 18 +++++++++++++----- vendor/modules.txt | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index cc5d90975..431dafc2a 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/valyala/fastjson v1.6.3 github.com/valyala/fastrand v1.1.0 github.com/valyala/fasttemplate v1.2.1 - github.com/valyala/gozstd v1.13.0 + github.com/valyala/gozstd v1.14.1 github.com/valyala/quicktemplate v1.7.0 golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 diff --git a/go.sum b/go.sum index a5f1ca7ff..6d65065ee 100644 --- a/go.sum +++ b/go.sum @@ -958,8 +958,8 @@ github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002 github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/valyala/gozstd v1.13.0 h1:M9qgbElBZsHlh8a4jjHO4lY42xLJeb+KWVBwFBAapRo= -github.com/valyala/gozstd v1.13.0/go.mod h1:y5Ew47GLlP37EkTB+B4s7r6A5rdaeB7ftbl9zoYiIPQ= +github.com/valyala/gozstd v1.14.1 h1:xkPAeHe8U/w/ocS6PywjkH406lKdratZuxhb1UTgO/s= +github.com/valyala/gozstd v1.14.1/go.mod h1:y5Ew47GLlP37EkTB+B4s7r6A5rdaeB7ftbl9zoYiIPQ= github.com/valyala/histogram v1.1.2/go.mod h1:CZAr6gK9dbD7hYx2s8WSPh0p5x5wETjC+2b3PJVtEdg= github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ= github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY= diff --git a/vendor/github.com/valyala/gozstd/gozstd.go b/vendor/github.com/valyala/gozstd/gozstd.go index 4287778d5..cc9ffa467 100644 --- a/vendor/github.com/valyala/gozstd/gozstd.go +++ b/vendor/github.com/valyala/gozstd/gozstd.go @@ -123,7 +123,6 @@ func compress(cctx, cctxDict *cctxWrapper, dst, src []byte, cd *CDict, compressi // All OK. return dst[:dstLen+compressedSize] } - if C.ZSTD_getErrorCode(result) != C.ZSTD_error_dstSize_tooSmall { // Unexpected error. panic(fmt.Errorf("BUG: unexpected error during compression with cd=%p: %s", cd, errStr(result))) @@ -139,7 +138,12 @@ func compress(cctx, cctxDict *cctxWrapper, dst, src []byte, cd *CDict, compressi result := compressInternal(cctx, cctxDict, dst[dstLen:dstLen+compressBound], src, cd, compressionLevel, true) compressedSize := int(result) - return dst[:dstLen+compressedSize] + dst = dst[:dstLen+compressedSize] + if cap(dst)-len(dst) > 4096 { + // Re-allocate dst in order to remove superflouos capacity and reduce memory usage. + dst = append([]byte{}, dst...) + } + return dst } func compressInternal(cctx, cctxDict *cctxWrapper, dst, src []byte, cd *CDict, compressionLevel int, mustSucceed bool) C.size_t { @@ -234,7 +238,7 @@ func decompress(dctx, dctxDict *dctxWrapper, dst, src []byte, dd *DDict) ([]byte } dstLen := len(dst) - if cap(dst)-dstLen >= len(src) { + if cap(dst) > dstLen { // Fast path - try decompressing without dst resize. result := decompressInternal(dctx, dctxDict, dst[dstLen:cap(dst)], src, dd) decompressedSize := int(result) @@ -270,8 +274,12 @@ func decompress(dctx, dctxDict *dctxWrapper, dst, src []byte, dd *DDict) ([]byte result := decompressInternal(dctx, dctxDict, dst[dstLen:dstLen+decompressBound], src, dd) decompressedSize := int(result) if decompressedSize >= 0 { - // All OK. - return dst[:dstLen+decompressedSize], nil + dst = dst[:dstLen+decompressedSize] + if cap(dst)-len(dst) > 4096 { + // Re-allocate dst in order to remove superflouos capacity and reduce memory usage. + dst = append([]byte{}, dst...) + } + return dst, nil } // Error during decompression. diff --git a/vendor/modules.txt b/vendor/modules.txt index 074db8b35..ad86590ee 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -208,7 +208,7 @@ github.com/valyala/fastrand # github.com/valyala/fasttemplate v1.2.1 ## explicit github.com/valyala/fasttemplate -# github.com/valyala/gozstd v1.13.0 +# github.com/valyala/gozstd v1.14.1 ## explicit github.com/valyala/gozstd # github.com/valyala/histogram v1.2.0