refactor(compress): move MT parameter update policy to Rust

Move the next-job parameter derivation in
ZSTDMT_updateCParams_whileCompressing() behind a scalar Rust projection. Rust
now reproduces the existing CCtx-parameter derivation and restores the active
frame's saved windowLog; C retains private MT/CCtx layouts, logging, and final
writes.

Expose the preprocessor-derived block-compressor exclusion mask through the
private C boundary so reduced builds keep their authoritative configuration.
Add C/Rust layout assertions and focused tests for window preservation and
strategy-exclusion routing.

Test Plan:
- `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check`
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings`
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings`
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets` (184 tests)
- `ulimit -v 41943040; make -j1`
- `ulimit -v 41943040; make -j1 -C tests test` (all upstream tests completed successfully)
- Standalone Rust unit linking remains unavailable without the C-owned bridge symbols; integrated build and upstream MT/API coverage passed.
This commit is contained in:
2026-07-20 09:07:40 +02:00
parent 870d6a2e40
commit 6d3da898de
3 changed files with 258 additions and 6 deletions
+2 -2
View File
@@ -3945,7 +3945,7 @@ U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
return ZSTD_rust_params_cycleLog(hashLog, (int)strat);
}
static U32 ZSTD_getCParamsExclusionMask(void);
U32 ZSTD_getCParamsExclusionMask(void);
/** ZSTD_adjustCParams_internal() :
* optimize `cPar` for a specified input (`srcSize` and `dictSize`).
@@ -4001,7 +4001,7 @@ enum {
ZSTD_RUST_PARAMS_EXCLUDE_DFAST = 1u << 6
};
static U32 ZSTD_getCParamsExclusionMask(void)
U32 ZSTD_getCParamsExclusionMask(void)
{
U32 mask = 0;
#ifdef ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR
+62 -3
View File
@@ -25,6 +25,53 @@
#include "zstd_ldm.h"
#include "zstdmt_compress.h"
/* The Rust parameter leaf receives only this scalar snapshot. Keep the
* private ZSTDMT_CCtx and ZSTD_CCtx_params layouts in this translation unit. */
typedef struct {
int compressionLevel;
int cctxSrcSizeHint;
U64 srcSizeHint;
size_t dictSize;
int mode;
int enableLdm;
U32 ldmDefaultWindowLog;
ZSTD_compressionParameters overrides;
int useRowMatchFinder;
U32 exclusionMask;
U32 savedWindowLog;
} ZSTDMT_RustCParamsUpdateProjection;
typedef char ZSTDMT_rust_cparams_update_projection_layout[
(offsetof(ZSTDMT_RustCParamsUpdateProjection, compressionLevel) == 0
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, cctxSrcSizeHint)
== sizeof(int)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, srcSizeHint)
== 2 * sizeof(int)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, dictSize) == 16
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, mode)
== (sizeof(void*) == 8 ? 24 : 20)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, enableLdm)
== (sizeof(void*) == 8 ? 28 : 24)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, ldmDefaultWindowLog)
== (sizeof(void*) == 8 ? 32 : 28)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, overrides)
== (sizeof(void*) == 8 ? 36 : 32)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, useRowMatchFinder)
== (sizeof(void*) == 8 ? 64 : 60)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, exclusionMask)
== (sizeof(void*) == 8 ? 68 : 64)
&& offsetof(ZSTDMT_RustCParamsUpdateProjection, savedWindowLog)
== (sizeof(void*) == 8 ? 72 : 68)
&& sizeof(ZSTDMT_RustCParamsUpdateProjection)
== (sizeof(void*) == 8 ? 80 : 72))
? 1 : -1];
ZSTD_compressionParameters ZSTD_rust_params_updateCParamsWhileCompressing(
ZSTDMT_RustCParamsUpdateProjection projection);
/* Defined in zstd_compress.c so all C translation units use the same
* preprocessor-derived block-compressor exclusion mask. */
U32 ZSTD_getCParamsExclusionMask(void);
/* Guards code to support resizing the SeqPool.
* We will want to resize the SeqPool to save memory in the future.
* Until then, comment the code out since it is unused.
@@ -2260,9 +2307,21 @@ void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_p
DEBUGLOG(5, "ZSTDMT_updateCParams_whileCompressing (level:%i)",
compressionLevel);
mtctx->params.compressionLevel = compressionLevel;
{ ZSTD_compressionParameters cParams = ZSTD_getCParamsFromCCtxParams(cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
cParams.windowLog = saved_wlog;
mtctx->params.cParams = cParams;
{ ZSTDMT_RustCParamsUpdateProjection const projection = {
cctxParams->compressionLevel,
cctxParams->srcSizeHint,
ZSTD_CONTENTSIZE_UNKNOWN,
0,
ZSTD_cpm_noAttachDict,
cctxParams->ldmParams.enableLdm,
ZSTD_LDM_DEFAULT_WINDOW_LOG,
cctxParams->cParams,
cctxParams->useRowMatchFinder,
ZSTD_getCParamsExclusionMask(),
saved_wlog
};
mtctx->params.cParams =
ZSTD_rust_params_updateCParamsWhileCompressing(projection);
}
}