zstd icon indicating copy to clipboard operation
zstd copied to clipboard

No compression option

Open archerian opened this issue 7 years ago • 4 comments

I'm working on a multi client publish/subscribe IoT targeted application based on MQTT, planning to compress payloads using ztsd. My largest data payloads are in the 200-500kb range, with some really small heartbeat type messages. For the heart beat messages, its nor worth compressing, so I send as-is and at the client side check to see if its a valid zstd payload looking at the return value of ZSTD_findDecompressedSize(). I was wondering if there is a way to send the data with no compression, and if so what the compressionLevel for it would be. It would be fine to add a few bytes overheard for the zstd frame, if it would save me CPU cycles due to no compression.

archerian avatar Feb 28 '19 02:02 archerian

Zstd won't attempt to compress data smaller than 7 bytes. I wouldn't expect compression of tiny data (say < 50 bytes) to eat up many CPU cycles, so long as you are reusing the ZSTD_CCtx*. If you aren't reusing the CCtx, then allocating and initializing the CCtx will be most of the cost, so I don't think you'd even see the compression in the profile.

You could try setting the compression level to ZSTD_minCLevel(), which will be in effect no compression, but I wouldn't expect too much CPU gains for very small data, only for large data.

terrelln avatar Feb 28 '19 20:02 terrelln

Thanks I will reuse the CCtx and set the compression level to ZSTD_minCLevel()

archerian avatar Mar 01 '19 02:03 archerian

Does level=0 mean there is some compression ? This is a bit unexpected, since, conventionally level=0 (should?) mean(s) no compression.

NikosAlexandris avatar Jul 31 '25 14:07 NikosAlexandris

Does level=0 mean there is some compression ? This is a bit unexpected, since, conventionally level=0 (should?) mean(s) no compression.

level 0 means "default level".

A lot of parameters have this convention that 0 means "default".

Cyan4973 avatar Aug 01 '25 00:08 Cyan4973