8000 Don't shrink window log when streaming with a dictionary by terrelln · Pull Request #2451 · facebook/zstd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't shrink window log when streaming with a dictionary #2451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions lib/compress/zstd_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,15 +1188,26 @@ ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
assert(ZSTD_checkCParams(cPar)==0);

if (dictSize && srcSize == ZSTD_CONTENTSIZE_UNKNOWN)
srcSize = minSrcSize;

switch (mode) {
case ZSTD_cpm_noAttachDict:
case ZSTD_cpm_unknown:
case ZSTD_cpm_noAttachDict:
/* If we don't know the source size, don't make any
* assumptions about it. We will already have selected
* smaller parameters if a dictionary is in use.
*/
break;
case ZSTD_cpm_createCDict:
/* Assume a small source size when creating a dictionary
* with an unkown source size.
*/
if (dictSize && srcSize == ZSTD_CONTENTSIZE_UNKNOWN)
srcSize = minSrcSize;
break;
case ZSTD_cpm_attachDict:
/* Dictionary has its own dedicated parameters which have
* already been selected. We are selecting parameters
* for only the source.
*/
dictSize = 0;
break;
default:
Expand All @@ -1213,7 +1224,8 @@ ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
ZSTD_highbit32(tSize-1) + 1;
if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
}
{ U32 const dictAndWindowLog = ZSTD_dictAndWindowLog(cPar.windowLog, (U64)srcSize, (U64)dictSize);
if (srcSize != ZSTD_CONTENTSIZE_UNKNOWN) {
U32 const dictAndWindowLog = ZSTD_dictAndWindowLog(cPar.windowLog, (U64)srcSize, (U64)dictSize);
U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy);
if (cPar.hashLog > dictAndWindowLog+1) cPar.hashLog = dictAndWindowLog+1;
if (cycleLog > dictAndWindowLog)
Expand Down Expand Up @@ -2955,9 +2967,9 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
}

/* ZSTD_writeSkippableFrame_advanced() :
* Writes out a skippable frame with the specified magic number variant (16 are supported),
* Writes out a skippable frame with the specified magic number variant (16 are supported),
* from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15, and the desired source data.
*
*
* Returns the total number of bytes written, or a ZSTD error code.
*/
size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
Expand Down
26 changes: 26 additions & 0 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,32 @@ static int basicUnitTests(U32 const seed, double compressibility)
free(dict);
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : ZSTD_getCParams() + dictionary ", testNb++);
{
ZSTD_compressionParameters const medium = ZSTD_getCParams(1, 16*1024-1, 0);
ZSTD_compressionParameters const large = ZSTD_getCParams(1, 128*1024-1, 0);
ZSTD_compressionParameters const smallDict = ZSTD_getCParams(1, 0, 400);
ZSTD_compressionParameters const mediumDict = ZSTD_getCParams(1, 0, 10000);
ZSTD_compressionParameters const largeDict = ZSTD_getCParams(1, 0, 100000);

assert(!memcmp(&smallDict, &mediumDict, sizeof(smallDict)));
assert(!memcmp(&medium, &mediumDict, sizeof(medium)));
assert(!memcmp(&large, &largeDict, sizeof(large)));
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : ZSTD_adjustCParams() + dictionary ", testNb++);
{
ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, 0, 0);
ZSTD_compressionParameters const smallDict = ZSTD_adjustCParams(cParams, 0, 400);
ZSTD_compressionParameters const smallSrcAndDict = ZSTD_adjustCParams(cParams, 500, 400);

assert(smallSrcAndDict.windowLog == 10);
assert(!memcmp(&cParams, &smallDict, sizeof(cParams)));
}
DISPLAYLEVEL(3, "OK \n");

#endif

_end:
Expand Down
9 changes: 9 additions & 0 deletions tests/regression/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ static config_t no_pledged_src_size = {
.no_pledged_src_size = 1,
};

static config_t no_pledged_src_size_with_dict = {
.name = "no source size with dict",
.cli_args = "",
.param_values = PARAM_VALUES(level_0_param_values),
.no_pledged_src_size = 1,
.use_dictionary = 1,
};

static param_value_t const ldm_param_values[] = {
{.param = ZSTD_c_enableLongDistanceMatching, .value = 1},
};
Expand Down Expand Up @@ -192,6 +200,7 @@ static config_t const* g_configs[] = {
#undef FAST_LEVEL

&no_pledged_src_size,
&no_pledged_src_size_with_dict,
&ldm,
&mt,
&mt_ldm,
Expand Down
17 changes: 17 additions & 0 deletions tests/regression/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,27 @@ data_t github = {
},
};

data_t github_tar = {
.name = "github.tar",
.type = data_type_file,
.data =
{
.url = REGRESSION_RELEASE("github.tar.zst"),
.xxhash64 = 0xa9b1b44b020df292LL,
},
.dict =
{
.url = REGRESSION_RELEASE("github.dict.zst"),
.xxhash64 = 0x1eddc6f737d3cb53LL,

},
};

static data_t* g_data[] = {
&silesia,
&silesia_tar,
&github,
&github_tar,
NULL,
};

Expand Down
Loading
0