]> git.ipfire.org Git - thirdparty/zstd.git/commit
Optimize decompression and fix wildcopy overread
authorNick Terrell <terrelln@fb.com>
Thu, 19 Sep 2019 20:25:03 +0000 (13:25 -0700)
committerNick Terrell <nickrterrell@gmail.com>
Fri, 20 Sep 2019 04:07:14 +0000 (21:07 -0700)
commitefd37a64eaff5a0a26ae2566fdb45dc4a0c91673
tree302df24c4ba1c861390ec2a0a03557216ba13953
parent0e76000dee228194235618ea9c7e9cc9ea85b600
Optimize decompression and fix wildcopy overread

* Bump `WILDCOPY_OVERLENGTH` to 16 to fix the wildcopy overread.
* Optimize `ZSTD_wildcopy()` by removing unnecessary branches and
  unrolling the loop.
* Extract `ZSTD_overlapCopy8()` into its own function.
* Add `ZSTD_safecopy()` for `ZSTD_execSequenceEnd()`. It is
  optimized for single long sequences, since that is the important
  case that can end up in `ZSTD_execSequenceEnd()`. Without this
  optimization, decompressing a block with 1 long match goes
  from 5.7 GB/s to 800 MB/s.
* Refactor `ZSTD_execSequenceEnd()`.
* Increase the literal copy shortcut to 16.
* Add a shortcut for offset >= 16.
* Simplify `ZSTD_execSequence()` by pushing more cases into
  `ZSTD_execSequenceEnd()`.
* Delete `ZSTD_execSequenceLong()` since it is exactly the
  same as `ZSTD_execSequence()`.

clang-8 seeds +17.5% on silesia and +21.8% on enwik8.
gcc-9 sees +12% on silesia and +15.5% on enwik8.

TODO: More detailed measurements, and on more datasets.

Crdit to OSS-Fuzz for finding the wildcopy overread.
lib/common/zstd_internal.h
lib/compress/zstd_compress_internal.h
lib/decompress/zstd_decompress_block.c