]> Cypherpunks repositories - gostls13.git/commit
compress/flate: add Reset() to allow reusing large buffers to compress multiple buffers
authorJames Robinson <jamesr@google.com>
Mon, 20 Oct 2014 01:58:02 +0000 (12:58 +1100)
committerNigel Tao <nigeltao@golang.org>
Mon, 20 Oct 2014 01:58:02 +0000 (12:58 +1100)
commit193d09a659c8d0a894fa682a879adb8fac1a4d82
treed1134db384888e5229d723e049721142f5e261b3
parent18c7fbdfd7a0842ca601231266b6582f957c982b
compress/flate: add Reset() to allow reusing large buffers to compress multiple buffers

This adds a Reset() to compress/flate's decompressor and plumbs that through
to compress/zlib and compress/gzip's Readers so callers can avoid large
allocations when performing many inflate operations. In particular this
preserves the allocation of the decompressor.hist buffer, which is 32kb and
overwritten as needed while inflating.

On the benchmark described in issue 6317, produces the following speedup on
my 2.3ghz Intel Core i7 MBP with go version devel +6b696a34e0af Sun Aug 03
15:14:59 2014 -0700 darwin/amd64:

blocked.text w/out patch vs blocked.text w/ patch:
benchmark           old ns/op      new ns/op      delta
BenchmarkGunzip     8371577533     7927917687     -5.30%

benchmark           old allocs     new allocs     delta
BenchmarkGunzip     176818         148519         -16.00%

benchmark           old bytes     new bytes     delta
BenchmarkGunzip     292184936     12739528      -95.64%

flat.text vs blocked.text w/patch:
benchmark           old ns/op      new ns/op      delta
BenchmarkGunzip     7939447827     7927917687     -0.15%

benchmark           old allocs     new allocs     delta
BenchmarkGunzip     90702          148519         +63.74%

benchmark           old bytes     new bytes     delta
BenchmarkGunzip     9959528       12739528      +27.91%

Similar speedups to those bradfitz saw in  https://golang.org/cl/13416045.

Fixes #6317.
Fixes #7950.

LGTM=nigeltao
R=golang-codereviews, bradfitz, dan.kortschak, adg, nigeltao, jamesr
CC=golang-codereviews
https://golang.org/cl/97140043
src/compress/flate/inflate.go
src/compress/flate/inflate_test.go [new file with mode: 0644]
src/compress/gzip/gunzip.go
src/compress/zlib/reader.go