Support negative Zstd compression levels#2874
Open
tillkruss wants to merge 1 commit into
Open
Conversation
OPT_COMPRESSION_LEVEL treated any value below 1 as "use the default",
so negative Zstd levels (e.g. -5) were silently replaced with the
default level 3. Zstd supports negative ("fast") compression levels,
so only 0 (the ecalloc default and Zstd's own "use default" sentinel)
should now map to the default; negative values are passed through to
ZSTD_compress, which clamps extreme values to ZSTD_minCLevel()
internally.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Member
|
The change is fine. Not sure we can merge it before phpredis 7.0 though. If many people are relying on |
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.
Summary
OPT_COMPRESSION_LEVELtreated any value below1as "use the default", so negative Zstd levels (e.g.-5) were silently discarded and replaced with the default level 3. Zstd supports negative ("fast") compression levels, so they should be honored.This changes the guard in the
REDIS_COMPRESSION_ZSTDbranch ofredis_compress()fromcompression_level < 1tocompression_level == 0:0— theecallocdefault and Zstd's own "use default" sentinel — still maps toZSTD_CLEVEL_DEFAULT(or3).ZSTD_compress().No lower-bound clamp is added:
ZSTD_compress()already clamps extreme negatives toZSTD_minCLevel()internally, andZSTD_minCLevel()only exists since libzstd 1.3.6 while phpredis supports ≥ 1.3.0 (config.m4), so calling it would break the build on older libzstd. The existing upper-bound clamp toZSTD_maxCLevel()is unchanged.Before
After