]> Cypherpunks.ru repositories - gostls13.git/commit
compress/flate, archive/zip: reduce memory allocations
authorMaksim Meshkov <subtle.byte.dev@gmail.com>
Wed, 24 May 2023 21:18:15 +0000 (21:18 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 24 May 2023 23:23:54 +0000 (23:23 +0000)
commit08458804fb6591397fe1c58f4e04fd490e70fbcb
tree490b0cbee6ebfd4ad8d531d00d01da4094b7c8c3
parenta965318ac051b112b61fcbbbfe4e0be00088abd7
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>
src/archive/zip/zip_test.go
src/compress/flate/inflate.go
src/compress/flate/inflate_test.go