Comments (5)
Hi @yxsamliu,
As you noted, the limiting factor here is likely the window size, which controls the maximum distance over which objects can be deduplicated. For level 6 it's 2 MB. For level 20 it's 32 MB. You can control this independently of the compression level, by setting the ZSTD_c_windowLog
compression parameter, although lower compression levels have increasingly limited abilities to take advantage of very long windows.
Zstd also has a search engine specifically targeting large matches at long distances: the long-distance matcher.
For your use case, I'd expect a moderate compression level with the long-distance matcher enabled on a large window size to perform well at significantly better speed than setting a very high compression level.
from zstd.
ZSTD_compressCCtx()
is ignoring advanced parameters :
* Important : in order to behave similarly to `ZSTD_compress()`,
* this function compresses at requested compression level,
* __ignoring any other parameter__ .
Use ZSTD_compress2()
instead :
* "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
* __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
from zstd.
If we assume that some relatively large portions (dozens of bytes at least) are very similar at byte level, but separated by significant distances, then indeed the long distance matcher would be my recommendation too. It's great at finding long matches at large distances, and the overall speed cost is reasonable. You wouldn't have to change the compression level.
Using the long distance matcher will also impact the window size automatically.
Be aware though that this mode automatically sets the window size to 128 MB by default, which might be too high. You can change that by being explicit about the window size you want.
from zstd.
Thanks for your advice. I tried the following code to specify both compression level and enable LDM:
void zstd::compress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &CompressedBuffer, int Level, bool EnableLdm) {
ZSTD_CCtx* Cctx = ZSTD_createCCtx();
if (!Cctx) report_bad_alloc_error("Failed to create ZSTD_CCtx");
size_t const LevelStatus = ZSTD_CCtx_setParameter(Cctx, ZSTD_c_compressionLevel, Level);
if (ZSTD_isError(LevelStatus)) {
ZSTD_freeCCtx(Cctx);
report_bad_alloc_error("Failed to set ZSTD_c_compressionLevel");
}
size_t const LdmStatus = ZSTD_CCtx_setParameter(Cctx, ZSTD_c_enableLongDistanceMatching, EnableLdm ? 1 : 0);
printf("LDM=%d\n", (int)EnableLdm);
if (ZSTD_isError(LdmStatus)) {
ZSTD_freeCCtx(Cctx);
report_bad_alloc_error("Failed to set ZSTD_c_enableLongDistanceMatching");
}
unsigned long CompressedBufferSize = ZSTD_compressBound(Input.size());
CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
size_t const CompressedSize = ZSTD_compressCCtx(
Cctx,
CompressedBuffer.data(), CompressedBufferSize,
Input.data(), Input.size(),
Level
);
ZSTD_freeCCtx(Cctx);
if (ZSTD_isError(CompressedSize))
report_bad_alloc_error("Compression failed");
__msan_unpoison(CompressedBuffer.data(), CompressedSize);
if (CompressedSize < CompressedBuffer.size())
CompressedBuffer.truncate(CompressedSize);
}
The compression level seems to take effect but LDM seems not. Strangely, using the zstd program with the same compression level and --long
, I can see --long
takes effect. Does my code missing some other parameters which makes LDM not taking effect? Thanks.
from zstd.
ZSTD_compressCCtx()
is ignoring advanced parameters :* Important : in order to behave similarly to `ZSTD_compress()`, * this function compresses at requested compression level, * __ignoring any other parameter__ .
Use
ZSTD_compress2()
instead :* "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` ! * __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
Thanks. It works.
from zstd.
Related Issues (20)
- Export "selected" CMake target for zstd HOT 5
- [Question] Understanding of compression level with external sequence producer HOT 2
- zstd fails to process some filenames on Windows [we need a hero] HOT 3
- We need a ZStd JavaScript library HOT 1
- Compiler warnings present when integrated with Swift Package Manager
- will zstd get nvcomp acceleration or a gpu support like g-brotli? HOT 1
- How can I change the window size? HOT 1
- Increase minimum C standard from C89/C90 to C11 HOT 3
- New zstd 1.5.5 version is two times slower in compression speed than older 1.4.5 version HOT 11
- ZSTD with T option does not scale on multicore CPUs HOT 7
- Question about FSE Huffman literal part
- C++ Builder and mem.h ambiguity HOT 7
- Reducing DCtx Size for Embedded Systems (like esp32) HOT 2
- Automatic code formatting? HOT 1
- No `uncompressed` and `ratio` information in `zstd --list` output if the zstd file is created via pipe HOT 3
- lz4 "legacy" format support HOT 1
- Add common file types that are compressed to ' --exclude-compressed' HOT 3
- windows
- Using ZSTD_compressBound for Streaming Input HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zstd.