From 86db60752d1f813642054d12d704663c7757d434 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 26 Feb 2024 13:27:59 -0800 Subject: [PATCH] optimization: bail out faster in presence of incompressible data --- lib/compress/zstd_compress_superblock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) */ -- 2.47.2