-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix up superblock mode #2100
Merged
Merged
Fix up superblock mode #2100
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1928,21 +1928,6 @@ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr) | |
mlCodeTable[seqStorePtr->longLengthPos] = MaxML; | ||
} | ||
|
||
static int ZSTD_disableLiteralsCompression(const ZSTD_CCtx_params* cctxParams) | ||
{ | ||
switch (cctxParams->literalCompressionMode) { | ||
case ZSTD_lcm_huffman: | ||
return 0; | ||
case ZSTD_lcm_uncompressed: | ||
return 1; | ||
default: | ||
assert(0 /* impossible: pre-validated */); | ||
/* fall-through */ | ||
case ZSTD_lcm_auto: | ||
return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0); | ||
} | ||
} | ||
|
||
/* ZSTD_useTargetCBlockSize(): | ||
* Returns if target compressed block size param is being used. | ||
* If used, compression will do best effort to make a compressed block size to be around targetCBlockSize. | ||
|
@@ -2387,6 +2372,18 @@ static int ZSTD_isRLE(const BYTE *ip, size_t length) { | |
return 1; | ||
} | ||
|
||
/* Returns true if the given block may be RLE. | ||
* This is just a heuristic based on the compressibility. | ||
* It may return both false positives and false negatives. | ||
*/ | ||
static int ZSTD_maybeRLE(seqStore_t const* seqStore) | ||
{ | ||
size_t const nbSeqs = (size_t)(seqStore->sequences - seqStore->sequencesStart); | ||
size_t const nbLits = (size_t)(seqStore->lit - seqStore->litStart); | ||
|
||
return nbSeqs < 4 && nbLits < 10; | ||
} | ||
|
||
static void ZSTD_confirmRepcodesAndEntropyTables(ZSTD_CCtx* zc) | ||
{ | ||
ZSTD_compressedBlockState_t* const tmp = zc->blockState.prevCBlock; | ||
|
@@ -2463,6 +2460,16 @@ static size_t ZSTD_compressBlock_targetCBlockSize_body(ZSTD_CCtx* zc, | |
{ | ||
DEBUGLOG(6, "Attempting ZSTD_compressSuperBlock()"); | ||
if (bss == ZSTDbss_compress) { | ||
if (/* We don't want to emit our first block as a RLE even if it qualifies because | ||
* doing so will cause the decoder (cli only) to throw a "should consume all input error." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
* This is only an issue for zstd <= v1.4.3 | ||
*/ | ||
!zc->isFirstBlock && | ||
ZSTD_maybeRLE(&zc->seqStore) && | ||
ZSTD_isRLE((BYTE const*)src, srcSize)) | ||
{ | ||
return ZSTD_rleCompressBlock(dst, dstCapacity, *(BYTE const*)src, srcSize, lastBlock); | ||
} | ||
/* Attempt superblock compression. | ||
* | ||
* Note that compressed size of ZSTD_compressSuperBlock() is not bound by the | ||
|
@@ -2481,12 +2488,15 @@ static size_t ZSTD_compressBlock_targetCBlockSize_body(ZSTD_CCtx* zc, | |
* * cSize >= blockBound(srcSize): We have expanded the block too much so | ||
* emit an uncompressed block. | ||
*/ | ||
size_t const cSize = ZSTD_compressSuperBlock(zc, dst, dstCapacity, lastBlock); | ||
if (cSize != ERROR(dstSize_tooSmall)) { | ||
FORWARD_IF_ERROR(cSize); | ||
if (cSize != 0 && cSize < srcSize + ZSTD_blockHeaderSize) { | ||
ZSTD_confirmRepcodesAndEntropyTables(zc); | ||
return cSize; | ||
{ | ||
size_t const cSize = ZSTD_compressSuperBlock(zc, dst, dstCapacity, src, srcSize, lastBlock); | ||
if (cSize != ERROR(dstSize_tooSmall)) { | ||
size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, zc->appliedParams.cParams.strategy); | ||
FORWARD_IF_ERROR(cSize); | ||
if (cSize != 0 && cSize < maxCSize + ZSTD_blockHeaderSize) { | ||
ZSTD_confirmRepcodesAndEntropyTables(zc); | ||
return cSize; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this function,
ZSTD_getSequenceLength()
, is only used withinzstd_compress_superblock.c
.Therefore, why is it implemented in
common/zstd_internal.h
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a generic helper function related to sequences. By putting it near the sequences, hopefully the next person who needs to read a litlen/matchlen will use this function, and see the reasoning behind it. A refactor of existing helper code, like the sequence collector, should switch it to using this function.