From: Yann Collet Date: Mon, 26 Feb 2024 21:27:59 +0000 (-0800) Subject: optimization: bail out faster in presence of incompressible data X-Git-Tag: v1.5.6^2~60^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86db60752d1f813642054d12d704663c7757d434;p=thirdparty%2Fzstd.git optimization: bail out faster in presence of incompressible data --- diff --git a/lib/compress/zstd_compress_superblock.c b/lib/compress/zstd_compress_superblock.c index e9038c472..a9e9493be 100644 --- a/lib/compress/zstd_compress_superblock.c +++ b/lib/compress/zstd_compress_superblock.c @@ -521,6 +521,9 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr, DEBUGLOG(5, "estimated fullblock size=%u bytes ; avgLitCost=%.2f ; avgSeqCost=%.2f ; targetCBlockSize=%u, nbSubBlocks=%u ; avgBlockBudget=%.0f bytes", (unsigned)ebs.estBlockSize, (double)avgLitCost/BYTESCALE, (double)avgSeqCost/BYTESCALE, (unsigned)targetCBlockSize, (unsigned)nbSubBlocks, (double)avgBlockBudget/BYTESCALE); + /* simplification: if estimates states that the full superblock doesn't compress, just bail out immediately + * this will result in the production of a single uncompressed block covering @srcSize.*/ + if (ebs.estBlockSize > srcSize) return 0; /* compress and write sub-blocks */ for (n=0; n+1 < nbSubBlocks; n++) { @@ -568,7 +571,7 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr, sp += seqCount; blockBudgetSupp = 0; } } - /* otherwise : do not compress yet, coalesce current block with next one */ + /* otherwise : do not compress yet, coalesce current sub-block with following one */ } } /* if (nbSeqs > 0) */