From 2e4db3e531e224118a316d50174300116a2f99ca Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 24 May 2017 13:15:19 -0700 Subject: [PATCH] fixed performance regression with ZSTD_decompress() on small files memset() was a quick fix to initialization problems, but initialize too much space (tables, buffers) which show up in decompression speed of ZSTD_decompress() since it needs to recreate DCtx at each invocation. Fixed by only initialization relevant pointers and size fields. --- lib/decompress/zstd_decompress.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index aabfa6d94..8cf500445 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -195,11 +195,16 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem) dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(ZSTD_DCtx), customMem); if (!dctx) return NULL; - memset(dctx, 0, sizeof(*dctx)); memcpy(&dctx->customMem, &customMem, sizeof(customMem)); ZSTD_decompressBegin(dctx); /* cannot fail */ dctx->streamStage = zdss_init; dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT; + dctx->ddict = NULL; + dctx->ddictLocal = NULL; + dctx->inBuff = NULL; + dctx->outBuff = NULL; + dctx->inBuffSize = 0; + dctx->outBuffSize= 0; return dctx; }