• James Robinson's avatar
    compress/flate: add Reset() to allow reusing large buffers to compress multiple buffers · 193d09a6
    James Robinson authored
    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
    193d09a6
Name
Last commit
Last update
..
copy.go Loading commit data...
copy_test.go Loading commit data...
deflate.go Loading commit data...
deflate_test.go Loading commit data...
fixedhuff.go Loading commit data...
flate_test.go Loading commit data...
gen.go Loading commit data...
huffman_bit_writer.go Loading commit data...
huffman_code.go Loading commit data...
inflate.go Loading commit data...
inflate_test.go Loading commit data...
reader_test.go Loading commit data...
reverse_bits.go Loading commit data...
token.go Loading commit data...
writer_test.go Loading commit data...