Merge pull request #580 from facebook/speedStream
Improve streaming decompression speed
This commit is contained in:
@@ -1469,8 +1469,7 @@ size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
|
|||||||
if (ZSTD_isError(headerSize)) return headerSize;
|
if (ZSTD_isError(headerSize)) return headerSize;
|
||||||
|
|
||||||
/* Frame Header */
|
/* Frame Header */
|
||||||
{
|
{ size_t const ret = ZSTD_getFrameParams(&fParams, ip, remainingSize);
|
||||||
size_t const ret = ZSTD_getFrameParams(&fParams, ip, remainingSize);
|
|
||||||
if (ZSTD_isError(ret)) return ret;
|
if (ZSTD_isError(ret)) return ret;
|
||||||
if (ret > 0) return ERROR(srcSize_wrong);
|
if (ret > 0) return ERROR(srcSize_wrong);
|
||||||
}
|
}
|
||||||
@@ -1503,7 +1502,7 @@ size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! ZSTD_decompressFrame() :
|
/*! ZSTD_decompressFrame() :
|
||||||
* `dctx` must be properly initialized */
|
* @dctx must be properly initialized */
|
||||||
static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
||||||
void* dst, size_t dstCapacity,
|
void* dst, size_t dstCapacity,
|
||||||
const void** srcPtr, size_t *srcSizePtr)
|
const void** srcPtr, size_t *srcSizePtr)
|
||||||
@@ -1570,7 +1569,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|||||||
remainingSize -= 4;
|
remainingSize -= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow caller to get size read
|
/* Allow caller to get size read */
|
||||||
*srcPtr = ip;
|
*srcPtr = ip;
|
||||||
*srcSizePtr = remainingSize;
|
*srcSizePtr = remainingSize;
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
@@ -2100,7 +2099,7 @@ size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
|
|||||||
{
|
{
|
||||||
/* pass content and size in case legacy frames are encountered */
|
/* pass content and size in case legacy frames are encountered */
|
||||||
return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
|
return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
|
||||||
ddict->dictContent, ddict->dictSize,
|
NULL, 0,
|
||||||
ddict);
|
ddict);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2301,6 +2300,21 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|||||||
break;
|
break;
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
/* check for single-pass mode opportunity */
|
||||||
|
if (zds->fParams.frameContentSize && zds->fParams.windowSize /* skippable frame if == 0 */
|
||||||
|
&& (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
|
||||||
|
size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
|
||||||
|
if (cSize <= (size_t)(iend-istart)) {
|
||||||
|
size_t const decompressedSize = ZSTD_decompress_usingDDict(zds->dctx, op, oend-op, istart, cSize, zds->ddict);
|
||||||
|
if (ZSTD_isError(decompressedSize)) return decompressedSize;
|
||||||
|
ip = istart + cSize;
|
||||||
|
op += decompressedSize;
|
||||||
|
zds->dctx->expected = 0;
|
||||||
|
zds->stage = zdss_init;
|
||||||
|
someMoreWork = 0;
|
||||||
|
break;
|
||||||
|
} }
|
||||||
|
|
||||||
/* Consume header */
|
/* Consume header */
|
||||||
ZSTD_refDDict(zds->dctx, zds->ddict);
|
ZSTD_refDDict(zds->dctx, zds->ddict);
|
||||||
{ size_t const h1Size = ZSTD_nextSrcSizeToDecompress(zds->dctx); /* == ZSTD_frameHeaderSize_prefix */
|
{ size_t const h1Size = ZSTD_nextSrcSizeToDecompress(zds->dctx); /* == ZSTD_frameHeaderSize_prefix */
|
||||||
|
|||||||
+12
-8
@@ -108,6 +108,7 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
void* const CNBuffer = malloc(CNBuffSize);
|
void* const CNBuffer = malloc(CNBuffSize);
|
||||||
void* const compressedBuffer = malloc(ZSTD_compressBound(CNBuffSize));
|
void* const compressedBuffer = malloc(ZSTD_compressBound(CNBuffSize));
|
||||||
void* const decodedBuffer = malloc(CNBuffSize);
|
void* const decodedBuffer = malloc(CNBuffSize);
|
||||||
|
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
||||||
int testResult = 0;
|
int testResult = 0;
|
||||||
U32 testNb=0;
|
U32 testNb=0;
|
||||||
size_t cSize;
|
size_t cSize;
|
||||||
@@ -155,6 +156,16 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
} }
|
} }
|
||||||
DISPLAYLEVEL(4, "OK \n");
|
DISPLAYLEVEL(4, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(4, "test%3i : decompress with null dict : ", testNb++);
|
||||||
|
{ size_t const r = ZSTD_decompress_usingDict(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize, NULL, 0);
|
||||||
|
if (r != CNBuffSize) goto _output_error; }
|
||||||
|
DISPLAYLEVEL(4, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(4, "test%3i : decompress with null DDict : ", testNb++);
|
||||||
|
{ size_t const r = ZSTD_decompress_usingDDict(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize, NULL);
|
||||||
|
if (r != CNBuffSize) goto _output_error; }
|
||||||
|
DISPLAYLEVEL(4, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(4, "test%3i : decompress with 1 missing byte : ", testNb++);
|
DISPLAYLEVEL(4, "test%3i : decompress with 1 missing byte : ", testNb++);
|
||||||
{ size_t const r = ZSTD_decompress(decodedBuffer, CNBuffSize, compressedBuffer, cSize-1);
|
{ size_t const r = ZSTD_decompress(decodedBuffer, CNBuffSize, compressedBuffer, cSize-1);
|
||||||
if (!ZSTD_isError(r)) goto _output_error;
|
if (!ZSTD_isError(r)) goto _output_error;
|
||||||
@@ -210,7 +221,6 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
/* Dictionary and CCtx Duplication tests */
|
/* Dictionary and CCtx Duplication tests */
|
||||||
{ ZSTD_CCtx* const ctxOrig = ZSTD_createCCtx();
|
{ ZSTD_CCtx* const ctxOrig = ZSTD_createCCtx();
|
||||||
ZSTD_CCtx* const ctxDuplicated = ZSTD_createCCtx();
|
ZSTD_CCtx* const ctxDuplicated = ZSTD_createCCtx();
|
||||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
|
||||||
static const size_t dictSize = 551;
|
static const size_t dictSize = 551;
|
||||||
|
|
||||||
DISPLAYLEVEL(4, "test%3i : copy context too soon : ", testNb++);
|
DISPLAYLEVEL(4, "test%3i : copy context too soon : ", testNb++);
|
||||||
@@ -283,12 +293,10 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
|
|
||||||
ZSTD_freeCCtx(ctxOrig);
|
ZSTD_freeCCtx(ctxOrig);
|
||||||
ZSTD_freeCCtx(ctxDuplicated);
|
ZSTD_freeCCtx(ctxDuplicated);
|
||||||
ZSTD_freeDCtx(dctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dictionary and dictBuilder tests */
|
/* Dictionary and dictBuilder tests */
|
||||||
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
|
||||||
size_t dictSize = 16 KB;
|
size_t dictSize = 16 KB;
|
||||||
void* dictBuffer = malloc(dictSize);
|
void* dictBuffer = malloc(dictSize);
|
||||||
size_t const totalSampleSize = 1 MB;
|
size_t const totalSampleSize = 1 MB;
|
||||||
@@ -370,14 +378,12 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
DISPLAYLEVEL(4, "OK \n");
|
DISPLAYLEVEL(4, "OK \n");
|
||||||
|
|
||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
ZSTD_freeDCtx(dctx);
|
|
||||||
free(dictBuffer);
|
free(dictBuffer);
|
||||||
free(samplesSizes);
|
free(samplesSizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* COVER dictionary builder tests */
|
/* COVER dictionary builder tests */
|
||||||
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
|
||||||
size_t dictSize = 16 KB;
|
size_t dictSize = 16 KB;
|
||||||
size_t optDictSize = dictSize;
|
size_t optDictSize = dictSize;
|
||||||
void* dictBuffer = malloc(dictSize);
|
void* dictBuffer = malloc(dictSize);
|
||||||
@@ -414,7 +420,7 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
memset(¶ms, 0, sizeof(params));
|
memset(¶ms, 0, sizeof(params));
|
||||||
params.steps = 4;
|
params.steps = 4;
|
||||||
optDictSize = COVER_optimizeTrainFromBuffer(dictBuffer, optDictSize,
|
optDictSize = COVER_optimizeTrainFromBuffer(dictBuffer, optDictSize,
|
||||||
CNBuffer, samplesSizes, nbSamples,
|
CNBuffer, samplesSizes, nbSamples / 4,
|
||||||
¶ms);
|
¶ms);
|
||||||
if (ZDICT_isError(optDictSize)) goto _output_error;
|
if (ZDICT_isError(optDictSize)) goto _output_error;
|
||||||
DISPLAYLEVEL(4, "OK, created dictionary of size %u \n", (U32)optDictSize);
|
DISPLAYLEVEL(4, "OK, created dictionary of size %u \n", (U32)optDictSize);
|
||||||
@@ -425,7 +431,6 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
DISPLAYLEVEL(4, "OK : %u \n", dictID);
|
DISPLAYLEVEL(4, "OK : %u \n", dictID);
|
||||||
|
|
||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
ZSTD_freeDCtx(dctx);
|
|
||||||
free(dictBuffer);
|
free(dictBuffer);
|
||||||
free(samplesSizes);
|
free(samplesSizes);
|
||||||
}
|
}
|
||||||
@@ -445,7 +450,6 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
|
|
||||||
/* block API tests */
|
/* block API tests */
|
||||||
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
{ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
|
||||||
static const size_t dictSize = 65 KB;
|
static const size_t dictSize = 65 KB;
|
||||||
static const size_t blockSize = 100 KB; /* won't cause pb with small dict size */
|
static const size_t blockSize = 100 KB; /* won't cause pb with small dict size */
|
||||||
size_t cSize2;
|
size_t cSize2;
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
|
|||||||
outBuff.pos = 0;
|
outBuff.pos = 0;
|
||||||
{ size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff);
|
{ size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff);
|
||||||
if (r != 0) goto _output_error; }
|
if (r != 0) goto _output_error; }
|
||||||
if (outBuff.pos != 0) goto _output_error; /* skippable frame len is 0 */
|
if (outBuff.pos != 0) goto _output_error; /* skippable frame output len is 0 */
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
/* Basic decompression test */
|
/* Basic decompression test */
|
||||||
|
|||||||
Reference in New Issue
Block a user