@@ -323,7 +323,7 @@ static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
323
323
assert (cctxParams .ldmParams .hashLog >= cctxParams .ldmParams .bucketSizeLog );
324
324
assert (cctxParams .ldmParams .hashRateLog < 32 );
325
325
}
326
- cctxParams .useBlockSplitter = ZSTD_resolveBlockSplitterMode (cctxParams .useBlockSplitter , & cParams );
326
+ cctxParams .postBlockSplitter = ZSTD_resolveBlockSplitterMode (cctxParams .postBlockSplitter , & cParams );
327
327
cctxParams .useRowMatchFinder = ZSTD_resolveRowMatchFinderMode (cctxParams .useRowMatchFinder , & cParams );
328
328
cctxParams .validateSequences = ZSTD_resolveExternalSequenceValidation (cctxParams .validateSequences );
329
329
cctxParams .maxBlockSize = ZSTD_resolveMaxBlockSize (cctxParams .maxBlockSize );
@@ -391,13 +391,13 @@ ZSTD_CCtxParams_init_internal(ZSTD_CCtx_params* cctxParams,
391
391
*/
392
392
cctxParams -> compressionLevel = compressionLevel ;
393
393
cctxParams -> useRowMatchFinder = ZSTD_resolveRowMatchFinderMode (cctxParams -> useRowMatchFinder , & params -> cParams );
394
- cctxParams -> useBlockSplitter = ZSTD_resolveBlockSplitterMode (cctxParams -> useBlockSplitter , & params -> cParams );
394
+ cctxParams -> postBlockSplitter = ZSTD_resolveBlockSplitterMode (cctxParams -> postBlockSplitter , & params -> cParams );
395
395
cctxParams -> ldmParams .enableLdm = ZSTD_resolveEnableLdm (cctxParams -> ldmParams .enableLdm , & params -> cParams );
396
396
cctxParams -> validateSequences = ZSTD_resolveExternalSequenceValidation (cctxParams -> validateSequences );
397
397
cctxParams -> maxBlockSize = ZSTD_resolveMaxBlockSize (cctxParams -> maxBlockSize );
398
398
cctxParams -> searchForExternalRepcodes = ZSTD_resolveExternalRepcodeSearch (cctxParams -> searchForExternalRepcodes , compressionLevel );
399
399
DEBUGLOG (4 , "ZSTD_CCtxParams_init_internal: useRowMatchFinder=%d, useBlockSplitter=%d ldm=%d" ,
400
- cctxParams -> useRowMatchFinder , cctxParams -> useBlockSplitter , cctxParams -> ldmParams .enableLdm );
400
+ cctxParams -> useRowMatchFinder , cctxParams -> postBlockSplitter , cctxParams -> ldmParams .enableLdm );
401
401
}
402
402
403
403
size_t ZSTD_CCtxParams_init_advanced (ZSTD_CCtx_params * cctxParams , ZSTD_parameters params )
@@ -598,11 +598,16 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
598
598
bounds .upperBound = 1 ;
599
599
return bounds ;
600
600
601
- case ZSTD_c_useBlockSplitter :
601
+ case ZSTD_c_splitAfterSequences :
602
602
bounds .lowerBound = (int )ZSTD_ps_auto ;
603
603
bounds .upperBound = (int )ZSTD_ps_disable ;
604
604
return bounds ;
605
605
606
+ case ZSTD_c_blockSplitterLevel :
607
+ bounds .lowerBound = 0 ;
608
+ bounds .upperBound = ZSTD_BLOCKSPLITTER_LEVEL_MAX ;
609
+ return bounds ;
610
+
606
611
case ZSTD_c_useRowMatchFinder :
607
612
bounds .lowerBound = (int )ZSTD_ps_auto ;
608
613
bounds .upperBound = (int )ZSTD_ps_disable ;
@@ -669,6 +674,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
669
674
case ZSTD_c_minMatch :
670
675
case ZSTD_c_targetLength :
671
676
case ZSTD_c_strategy :
677
+ case ZSTD_c_blockSplitterLevel :
672
678
return 1 ;
673
679
674
680
case ZSTD_c_format :
@@ -695,7 +701,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
695
701
case ZSTD_c_stableOutBuffer :
696
702
case ZSTD_c_blockDelimiters :
697
703
case ZSTD_c_validateSequences :
698
- case ZSTD_c_useBlockSplitter :
704
+ case ZSTD_c_splitAfterSequences :
699
705
case ZSTD_c_useRowMatchFinder :
700
706
case ZSTD_c_deterministicRefPrefix :
701
707
case ZSTD_c_prefetchCDictTables :
@@ -754,7 +760,8 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
754
760
case ZSTD_c_stableOutBuffer :
755
761
case ZSTD_c_blockDelimiters :
756
762
case ZSTD_c_validateSequences :
757
- case ZSTD_c_useBlockSplitter :
763
+ case ZSTD_c_splitAfterSequences :
764
+ case ZSTD_c_blockSplitterLevel :
758
765
case ZSTD_c_useRowMatchFinder :
759
766
case ZSTD_c_deterministicRefPrefix :
760
767
case ZSTD_c_prefetchCDictTables :
@@ -975,10 +982,15 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
975
982
CCtxParams -> validateSequences = value ;
976
983
return (size_t )CCtxParams -> validateSequences ;
977
984
978
- case ZSTD_c_useBlockSplitter :
979
- BOUNDCHECK (ZSTD_c_useBlockSplitter , value );
980
- CCtxParams -> useBlockSplitter = (ZSTD_paramSwitch_e )value ;
981
- return CCtxParams -> useBlockSplitter ;
985
+ case ZSTD_c_splitAfterSequences :
986
+ BOUNDCHECK (ZSTD_c_splitAfterSequences , value );
987
+ CCtxParams -> postBlockSplitter = (ZSTD_paramSwitch_e )value ;
988
+ return CCtxParams -> postBlockSplitter ;
989
+
990
+ case ZSTD_c_blockSplitterLevel :
991
+ BOUNDCHECK (ZSTD_c_blockSplitterLevel , value );
992
+ CCtxParams -> preBlockSplitter_level = value ;
993
+ return (size_t )CCtxParams -> preBlockSplitter_level ;
982
994
983
995
case ZSTD_c_useRowMatchFinder :
984
996
BOUNDCHECK (ZSTD_c_useRowMatchFinder , value );
@@ -1135,8 +1147,11 @@ size_t ZSTD_CCtxParams_getParameter(
1135
1147
case ZSTD_c_validateSequences :
1136
1148
* value = (int )CCtxParams -> validateSequences ;
1137
1149
break ;
1138
- case ZSTD_c_useBlockSplitter :
1139
- * value = (int )CCtxParams -> useBlockSplitter ;
1150
+ case ZSTD_c_splitAfterSequences :
1151
+ * value = (int )CCtxParams -> postBlockSplitter ;
1152
+ break ;
1153
+ case ZSTD_c_blockSplitterLevel :
1154
+ * value = CCtxParams -> preBlockSplitter_level ;
1140
1155
break ;
1141
1156
case ZSTD_c_useRowMatchFinder :
1142
1157
* value = (int )CCtxParams -> useRowMatchFinder ;
@@ -2099,7 +2114,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
2099
2114
{
2100
2115
ZSTD_cwksp * const ws = & zc -> workspace ;
2101
2116
DEBUGLOG (4 , "ZSTD_resetCCtx_internal: pledgedSrcSize=%u, wlog=%u, useRowMatchFinder=%d useBlockSplitter=%d" ,
2102
- (U32 )pledgedSrcSize , params -> cParams .windowLog , (int )params -> useRowMatchFinder , (int )params -> useBlockSplitter );
2117
+ (U32 )pledgedSrcSize , params -> cParams .windowLog , (int )params -> useRowMatchFinder , (int )params -> postBlockSplitter );
2103
2118
assert (!ZSTD_isError (ZSTD_checkCParams (params -> cParams )));
2104
2119
2105
2120
zc -> isFirstBlock = 1 ;
@@ -2111,7 +2126,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
2111
2126
params = & zc -> appliedParams ;
2112
2127
2113
2128
assert (params -> useRowMatchFinder != ZSTD_ps_auto );
2114
- assert (params -> useBlockSplitter != ZSTD_ps_auto );
2129
+ assert (params -> postBlockSplitter != ZSTD_ps_auto );
2115
2130
assert (params -> ldmParams .enableLdm != ZSTD_ps_auto );
2116
2131
assert (params -> maxBlockSize != 0 );
2117
2132
if (params -> ldmParams .enableLdm == ZSTD_ps_enable ) {
@@ -2517,10 +2532,10 @@ static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx,
2517
2532
/* Copy only compression parameters related to tables. */
2518
2533
params .cParams = srcCCtx -> appliedParams .cParams ;
2519
2534
assert (srcCCtx -> appliedParams .useRowMatchFinder != ZSTD_ps_auto );
2520
- assert (srcCCtx -> appliedParams .useBlockSplitter != ZSTD_ps_auto );
2535
+ assert (srcCCtx -> appliedParams .postBlockSplitter != ZSTD_ps_auto );
2521
2536
assert (srcCCtx -> appliedParams .ldmParams .enableLdm != ZSTD_ps_auto );
2522
2537
params .useRowMatchFinder = srcCCtx -> appliedParams .useRowMatchFinder ;
2523
- params .useBlockSplitter = srcCCtx -> appliedParams .useBlockSplitter ;
2538
+ params .postBlockSplitter = srcCCtx -> appliedParams .postBlockSplitter ;
2524
2539
params .ldmParams = srcCCtx -> appliedParams .ldmParams ;
2525
2540
params .fParams = fParams ;
2526
2541
params .maxBlockSize = srcCCtx -> appliedParams .maxBlockSize ;
@@ -2728,9 +2743,9 @@ static int ZSTD_useTargetCBlockSize(const ZSTD_CCtx_params* cctxParams)
2728
2743
* Returns 1 if true, 0 otherwise. */
2729
2744
static int ZSTD_blockSplitterEnabled (ZSTD_CCtx_params * cctxParams )
2730
2745
{
2731
- DEBUGLOG (5 , "ZSTD_blockSplitterEnabled (useBlockSplitter =%d)" , cctxParams -> useBlockSplitter );
2732
- assert (cctxParams -> useBlockSplitter != ZSTD_ps_auto );
2733
- return (cctxParams -> useBlockSplitter == ZSTD_ps_enable );
2746
+ DEBUGLOG (5 , "ZSTD_blockSplitterEnabled (postBlockSplitter =%d)" , cctxParams -> postBlockSplitter );
2747
+ assert (cctxParams -> postBlockSplitter != ZSTD_ps_auto );
2748
+ return (cctxParams -> postBlockSplitter == ZSTD_ps_enable );
2734
2749
}
2735
2750
2736
2751
/* Type returned by ZSTD_buildSequencesStatistics containing finalized symbol encoding types
@@ -4300,7 +4315,7 @@ ZSTD_compressBlock_splitBlock(ZSTD_CCtx* zc,
4300
4315
U32 nbSeq ;
4301
4316
size_t cSize ;
4302
4317
DEBUGLOG (4 , "ZSTD_compressBlock_splitBlock" );
4303
- assert (zc -> appliedParams .useBlockSplitter == ZSTD_ps_enable );
4318
+ assert (zc -> appliedParams .postBlockSplitter == ZSTD_ps_enable );
4304
4319
4305
4320
{ const size_t bss = ZSTD_buildSeqStore (zc , src , srcSize );
4306
4321
FORWARD_IF_ERROR (bss , "ZSTD_buildSeqStore failed" );
@@ -4491,7 +4506,7 @@ static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms,
4491
4506
4492
4507
#include "zstd_preSplit.h"
4493
4508
4494
- static size_t ZSTD_optimalBlockSize (ZSTD_CCtx * cctx , const void * src , size_t srcSize , size_t blockSizeMax , ZSTD_strategy strat , S64 savings )
4509
+ static size_t ZSTD_optimalBlockSize (ZSTD_CCtx * cctx , const void * src , size_t srcSize , size_t blockSizeMax , int splitLevel , ZSTD_strategy strat , S64 savings )
4495
4510
{
4496
4511
/* split level based on compression strategy, from `fast` to `btultra2` */
4497
4512
static const int splitLevels [] = { 0 , 0 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 4 };
@@ -4505,10 +4520,22 @@ static size_t ZSTD_optimalBlockSize(ZSTD_CCtx* cctx, const void* src, size_t src
4505
4520
* require verified savings to allow pre-splitting.
4506
4521
* Note: as a consequence, the first full block is not split.
4507
4522
*/
4508
- if (savings < 3 ) return 128 KB ;
4509
- /* dynamic splitting has a cpu cost for analysis,
4510
- * select a variant among multiple gradual speed/accuracy tradeoffs */
4511
- return ZSTD_splitBlock (src , blockSizeMax , splitLevels [strat ], cctx -> tmpWorkspace , cctx -> tmpWkspSize );
4523
+ if (savings < 3 ) {
4524
+ DEBUGLOG (6 , "don't attempt splitting: savings (%i) too low" , (int )savings );
4525
+ return 128 KB ;
4526
+ }
4527
+ /* apply @splitLevel, or use default value (which depends on @strat).
4528
+ * note that splitting heuristic is still conditioned by @savings >= 3,
4529
+ * so the first block will not reach this code path */
4530
+ if (splitLevel == 1 ) return 128 KB ;
4531
+ if (splitLevel == 0 ) {
4532
+ assert (ZSTD_fast <= strat && strat <= ZSTD_btultra2 );
4533
+ splitLevel = splitLevels [strat ];
4534
+ } else {
4535
+ assert (2 <= splitLevel && splitLevel <= 6 );
4536
+ splitLevel -= 2 ;
4537
+ }
4538
+ return ZSTD_splitBlock (src , blockSizeMax , splitLevel , cctx -> tmpWorkspace , cctx -> tmpWkspSize );
4512
4539
}
4513
4540
4514
4541
/*! ZSTD_compress_frameChunk() :
@@ -4539,7 +4566,12 @@ static size_t ZSTD_compress_frameChunk(ZSTD_CCtx* cctx,
4539
4566
4540
4567
while (remaining ) {
4541
4568
ZSTD_matchState_t * const ms = & cctx -> blockState .matchState ;
4542
- size_t const blockSize = ZSTD_optimalBlockSize (cctx , ip , remaining , blockSizeMax , cctx -> appliedParams .cParams .strategy , savings );
4569
+ size_t const blockSize = ZSTD_optimalBlockSize (cctx ,
4570
+ ip , remaining ,
4571
+ blockSizeMax ,
4572
+ cctx -> appliedParams .preBlockSplitter_level ,
4573
+ cctx -> appliedParams .cParams .strategy ,
4574
+ savings );
4543
4575
U32 const lastBlock = lastFrameChunk & (blockSize == remaining );
4544
4576
assert (blockSize <= remaining );
4545
4577
@@ -6286,7 +6318,7 @@ static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx,
6286
6318
dictSize , mode );
6287
6319
}
6288
6320
6289
- params .useBlockSplitter = ZSTD_resolveBlockSplitterMode (params .useBlockSplitter , & params .cParams );
6321
+ params .postBlockSplitter = ZSTD_resolveBlockSplitterMode (params .postBlockSplitter , & params .cParams );
6290
6322
params .ldmParams .enableLdm = ZSTD_resolveEnableLdm (params .ldmParams .enableLdm , & params .cParams );
6291
6323
params .useRowMatchFinder = ZSTD_resolveRowMatchFinderMode (params .useRowMatchFinder , & params .cParams );
6292
6324
params .validateSequences = ZSTD_resolveExternalSequenceValidation (params .validateSequences );
0 commit comments