Repository navigation
lib: add restrict qualifiers to row match finder - #4867
Xinlong-Chen wants to merge 1 commit into
Conversation
ZSTD_RowFindBestMatch() dominates level 8 compression. It mutates the hash and tag tables reachable through the match state while reading input and writing the selected offset. Without no-alias information, the compiler must conservatively account for overlap between these accesses. Add a portable ZSTD_RESTRICT macro and apply it only to the three pointer parameters that access data in the hot path. Leave iLimit and the read-only match counters unchanged. Benchmarking followed pts/compress-zstd-1.5.0, using zstd -T1 -b8 on its 1007 MiB FreeBSD 12.2 memstick image. The build used optimization flags widely adopted by major Linux distributions: -O2, LTO, and an x86-64-v2 baseline. Each base/opt pair was run for 10 counterbalanced rounds on a fixed CPU. The highest and lowest paired changes were discarded before aggregation. On AMD EPYC 7K62 (Zen 2), paired compression throughput improves by 3.21% with GCC 12 and 2.10% with GCC 16. On Intel Xeon Platinum 8255C (Cascade Lake), paired compression throughput improves by 1.71% with GCC 12 and 3.87% with GCC 16. For GCC 12 and GCC 16 respectively, the specialized hot function is 7.21% and 7.94% smaller, contains 8.56% and 6.41% fewer static instructions, and has 33.33% and 31.25% fewer explicit stack accesses. All runs produced identical compressed output, and decompression was unchanged within noise. The exact benefit depends on compiler code generation and the target microarchitecture. Co-authored-by: xionghuluo <xionghuluo@tencent.com> Signed-off-by: xinlongchen <xinlongchen@tencent.com>
|
Hi @Xinlong-Chen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
What and why
ZSTD_RowFindBestMatch()is a major level 8 compression hotspot. It updates the match state while reading input and writing the selected offset, but the compiler cannot currently assume these memory regions do not alias.This change adds a portable
ZSTD_RESTRICTmacro and applies it toms,ip, andoffsetPtr. Other compilers safely fall back to an empty macro.The benchmark follows
pts/compress-zstd-1.5.0:zstd -T1 -b8on its 1007 MiB FreeBSD 12.2 image. Builds use-O2, LTO, andx86-64-v2. Results are the average of eight paired samples after removing the largest and smallest changes from 10 counterbalanced rounds.Compression throughput improved across both tested CPUs:
For GCC 12/16, the hot function is 7.21%/7.94% smaller, with 8.56%/6.41% fewer static instructions and 33.33%/31.25% fewer explicit stack accesses.
All runs produced identical output; decompression was unchanged within noise. Performance gains vary by compiler and CPU.
Checklist
A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
Tools used
Cursor was used to assist with benchmark automation and drafting this description.