Repository navigation
lz4.c: faster extDict compression (branchless match selection) - #1967
Merged
Merged
Conversation
In extDict mode, each candidate is either in the dictionary or in the prefix. Small blocks see both kinds alternate unpredictably : with gcc, this branch missed often (perf, 16 KB blocks : 0.26 misses per byte, 0.11 in prefix mode). The match pointer is now selected without branch, in the match search and in the test of the next position, relative to dictEnd or source : it remains within its buffer (base can be NULL, when the address of source equals startIndex). lowLimit is set only once a match is found. clang already compiled it without branch. Output is unchanged (byte-identical). lz4 -b1 -D (64 KB dictionary, CDict path), silesia 32 MB, gcc 11, Zen 4 : - 4 KB blocks : 300 -> 387 MB/s (+29%) - 16 KB : 292 -> 395 MB/s (+35%) - 64 KB : 377 -> 421 MB/s (+12%) - 256 KB : -1% ; 1 MB : 465 -> 442 MB/s (-5%) ; 4 MB : 473 -> 446 MB/s (-5.7%) (beyond 64 KB, no candidate can be in the dictionary : the branch was well predicted) acceleration 3 : +12% to +28% from 4 to 64 KB. gcc 15 : +29% to +35% for 4-16 KB, -2.6% at 1 MB. clang 22 : neutral (within 1%). No dictionary : unchanged.
Cyan4973
force-pushed
the
extdict_speed
branch
from
October 28, 2026 00:14
7f4e50d to
6265968
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In extDict mode, dictionary and prefix candidates alternate unpredictably on small blocks : with gcc, choosing between them was a frequently mispredicted branch. The match pointer is now selected without branch, relative to
dictEndorsource(it remains within its buffer :basecan be NULL). clang already compiled it without branch. Output is byte-identical.lz4 -b1 -D(64 KB dictionary, CDict path), silesia 32 MB, gcc 11, Zen 4 :Beyond 64 KB, no candidate can be in the dictionary : the branch was well predicted there. Switching to prefix mode past 64 KB (future PR) would remove this cost.
Acceleration 3 : +12% to +28% (4-64 KB). gcc 15 : +29% to +35% (4-16 KB), -2.6% at 1 MB. clang 22 : neutral (within 1%). No dictionary : unchanged.