From: Yann Collet Date: Wed, 23 Oct 2024 21:11:49 +0000 (-0700) Subject: split all full 128 KB blocks X-Git-Tag: v1.5.7^2~71^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d3e5e3ba1007635fc991a3b208353463cb2712d;p=thirdparty%2Fzstd.git split all full 128 KB blocks this helps make the streaming behavior more consistent, since it does no longer depend on having more data presented on the input. suggested by @terrelln --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b064e382c..9de92cef2 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -4493,20 +4493,21 @@ static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms, static size_t ZSTD_optimalBlockSize(ZSTD_CCtx* cctx, const void* src, size_t srcSize, size_t blockSizeMax, ZSTD_strategy strat, S64 savings) { - /* note: conservatively only split full blocks (128 KB) currently, - * and even then only if there is more than 128 KB input remaining. + /* note: conservatively only split full blocks (128 KB) currently. + * While it's possible to go lower, let's keep it simple for a first implementation. + * Besides, benefits of splitting are reduced when blocks are already small. */ - if (srcSize <= 128 KB || blockSizeMax < 128 KB) + if (srcSize < 128 KB || blockSizeMax < 128 KB) return MIN(srcSize, blockSizeMax); /* dynamic splitting has a cpu cost for analysis, - * due to that cost it's only used for btlazy2+ strategies */ + * due to that cost it's only used for higher levels */ if (strat >= ZSTD_btopt) return ZSTD_splitBlock(src, srcSize, blockSizeMax, split_lvl2, cctx->tmpWorkspace, cctx->tmpWkspSize); if (strat >= ZSTD_lazy2) return ZSTD_splitBlock(src, srcSize, blockSizeMax, split_lvl1, cctx->tmpWorkspace, cctx->tmpWkspSize); /* blind split strategy - * no cpu cost, but can over-split homegeneous data. * heuristic, tested as being "generally better". + * no cpu cost, but can over-split homegeneous data. * do not split incompressible data though: respect the 3 bytes per block overhead limit. */ return savings ? 92 KB : 128 KB;