• Joe Tsai's avatar
    compress/flate: avoid large stack growth in fillDeflate · 9c3630f5
    Joe Tsai authored
    Ranging over an array causes the array to be copied over to the
    stack, which cause large re-growths. Instead, we should iterate
    over slices of the array.
    
    Also, assigning a large struct literal uses the stack even
    though the actual fields being populated are small in comparison
    to the entirety of the struct (see #18636).
    
    Fixing the stack growth does not alter CPU-time performance much
    since the stack-growth and copying was such a tiny portion of the
    compression work:
    
    name                         old time/op    new time/op    delta
    Encode/Digits/Default/1e4-8     332µs ± 1%     332µs ± 1%   ~     (p=0.796 n=10+10)
    Encode/Digits/Default/1e5-8    5.07ms ± 2%    5.05ms ± 1%   ~       (p=0.815 n=9+8)
    Encode/Digits/Default/1e6-8    53.7ms ± 1%    53.9ms ± 1%   ~     (p=0.075 n=10+10)
    Encode/Twain/Default/1e4-8      380µs ± 1%     380µs ± 1%   ~     (p=0.684 n=10+10)
    Encode/Twain/Default/1e5-8     5.79ms ± 2%    5.79ms ± 1%   ~      (p=0.497 n=9+10)
    Encode/Twain/Default/1e6-8     61.5ms ± 1%    61.8ms ± 1%   ~     (p=0.247 n=10+10)
    
    name                         old speed      new speed      delta
    Encode/Digits/Default/1e4-8  30.1MB/s ± 1%  30.1MB/s ± 1%   ~     (p=0.753 n=10+10)
    Encode/Digits/Default/1e5-8  19.7MB/s ± 2%  19.8MB/s ± 1%   ~       (p=0.795 n=9+8)
    Encode/Digits/Default/1e6-8  18.6MB/s ± 1%  18.5MB/s ± 1%   ~     (p=0.072 n=10+10)
    Encode/Twain/Default/1e4-8   26.3MB/s ± 1%  26.3MB/s ± 1%   ~     (p=0.616 n=10+10)
    Encode/Twain/Default/1e5-8   17.3MB/s ± 2%  17.3MB/s ± 1%   ~      (p=0.484 n=9+10)
    Encode/Twain/Default/1e6-8   16.3MB/s ± 1%  16.2MB/s ± 1%   ~     (p=0.238 n=10+10)
    
    Updates #18636
    Fixes #18625
    
    Change-Id: I471b20339bf675f63dc56d38b3acdd824fe23328
    Reviewed-on: https://go-review.googlesource.com/35122Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    9c3630f5
Name
Last commit
Last update
..
testdata Loading commit data...
deflate.go Loading commit data...
deflate_test.go Loading commit data...
deflatefast.go Loading commit data...
dict_decoder.go Loading commit data...
dict_decoder_test.go Loading commit data...
example_test.go Loading commit data...
flate_test.go Loading commit data...
huffman_bit_writer.go Loading commit data...
huffman_bit_writer_test.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...