diff options
author | Maksim Meshkov <subtle.byte.dev@gmail.com> | 2023-05-24 21:18:15 +0000 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-05-24 23:23:54 +0000 |
commit | 08458804fb6591397fe1c58f4e04fd490e70fbcb (patch) | |
tree | 490b0cbee6ebfd4ad8d531d00d01da4094b7c8c3 /src/archive | |
parent | a965318ac051b112b61fcbbbfe4e0be00088abd7 (diff) | |
download | go-08458804fb6591397fe1c58f4e04fd490e70fbcb.tar.gz go-08458804fb6591397fe1c58f4e04fd490e70fbcb.zip |
compress/flate, archive/zip: reduce memory allocations
The existing implementation allocates a new 4KB buffer each time it opens flate-encoded file in a zip archive. This commit allows the flate reader to reuse the buffer on call Reset instead of allocating a new one.
It is noticeable when a zip archive contains a huge amount of files, e.g. zip archive has 50_000 files, for each file 4KB buffer is allocated, so it is 200MB memory allocations. If files are read sequentially only one buffer is needed.
Fixes #59774
Change-Id: Ib16336b101ba58e8f0f30a45dc5fd4eeebc801a1
GitHub-Last-Rev: f3f395b2ad95b7ad7ce9df6f5e49c7b6a0627627
GitHub-Pull-Request: golang/go#59775
Reviewed-on: https://go-review.googlesource.com/c/go/+/487675
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/archive')
-rw-r--r-- | src/archive/zip/zip_test.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/archive/zip/zip_test.go b/src/archive/zip/zip_test.go index a4b952efcc..7d1de07c98 100644 --- a/src/archive/zip/zip_test.go +++ b/src/archive/zip/zip_test.go @@ -30,7 +30,7 @@ func TestOver65kFiles(t *testing.T) { for i := 0; i < nFiles; i++ { _, err := w.CreateHeader(&FileHeader{ Name: fmt.Sprintf("%d.dat", i), - Method: Store, // avoid Issue 6136 and Issue 6138 + Method: Store, // Deflate is too slow when it is compiled with -race flag }) if err != nil { t.Fatalf("creating file %d: %v", i, err) |