139 points · by felixhandte · 7y ago · 87 comments
Bullshit, Zstd was open-source from the very beginning, they just hired Yann and moved the project under facebook org. How do I know? I have written the JVM bindings [1] since v0.1 that are now used by Spark, Kafka, etc.
EDIT: Actually, my initial bindings were against v0.0.2 [2]
Kudos to FB for hiring him and helping Zstd getting production ready. This is just a PR false claim.
[1] https://github.com/luben/zstd-jni
[2] https://github.com/luben/zstd-jni/commit/3dfe760cbb8cc46da32...
The response had a header: content-encoding: gzip
Zstandard looks like an improvement of DEFLATE (= gzip = zlib) and its specification is only 3x longer (even though it is introduced 22 years later): https://tools.ietf.org/html/rfc8478
Since Zstandard is so simple and efficient, I thought it would get into browsers very quickly. Then, it could make sense to compress even PNG or JPG images, which are usually impossible to compress with DEFLATE.
Usual users have internet speeds of a 10 MB/s or so, and brotli is more favorable up to around 200 MB/s (2 gbps) internet speeds. It is also not just about speed, but mobile users need to pay less with brotli as less bytes are transferred.
Further (I'm not an expert on this, somewhat speculative) but likely the streaming properties of brotli are slightly better, i.e., less bytes are needed to hide in a buffer to be able to decode bytes. This may allow the browser to issue new fetches for urls in an html document earlier with brotli than with zstd.
According to this chart, Zstandard has a better compression ratio, while compressing and decompressing faster than Brotli: https://facebook.github.io/zstd/
At higher quality settings brotli wins in compression density, and particularly so with quality 11 or with short files.
Quality 0 is an irrelevant corner case of maximal compression speed, and is completely impractical for most uses.
If you plot the whole curve, brotli's density is above that of zstd's for compression speed/density -- when both algos are used with same backward reference window size.
It is nice to have disk IO be the limiting factor on decompression even when you are using NVMe drives.
Did that 4 years ago.
> The snappy wrapper can serve as a frontend for bzip2, lz4, lz4hc, lzma, lzo, and zlib.
> The zlib wrapper can serve as a frontend for bzip2, lz4, lz4hc, lzma, lzo, and snappy.
Very handy for quickly benchmarking multiple compressors without having to write multiple implementations of the same test code. As illustrated here http://www.lmdb.tech/bench/inmem/compress/
Feel free to PR support for brotli or zstd or anything else that comes along.
I have seen some fopencookie(3)-based zstd/zlib/xz/etc FILE-object wrappers floating around that make it pretty easy to work with any compression library's streaming APIs.
Unfortunately, we have a strict requirement that the decompression be done in pure Java (and ideally providing an InputStream interface). The official Brotli repo includes a pure Java decompression library that took about three lines of code to drop in next to our gzip support, while zstd had nothing suitable (a JNI wrapper is not an option, and the Java decompressor at [1] does not provide an streaming interface). Writing my own Java decompressor for zstd sounded like a fun project, but that would have been too much like yak shaving; brotli is good enough.
[1] https://github.com/airlift/aircompressor/tree/master/src/mai...
I never was able to locate a file that compresses better with zstd than with brotli, if you use the same window size in both.
The car analogy in using different window sizes is to drive on 1st gear with one car and drive on 5th gear with other, i.e., meaningless comparisons. One needs to use the same window size with both algos to be able to understand the performance potential in them. When one does that, brotli always wins in density and most of the time on compression speed to a given density. Zstd wins in decompression speed, but neither of them is slow (think 600 MB/s vs. 900 MB/s).
https://github.com/google/brotli/issues/642 is relatively well conducted, but covers the slow+dense and large window compression only.
I am working on that very question! Zstd's support for creating and using custom dictionaries opens the door to significant efficiencies. As described in the post though, dictionaries make compression a more complicated thing to use, and so there are lots of questions about how to apply that to the public internet in a way that's cross-compatible and secure. In short: it's something we're actively exploring.
[1] http://quixdb.github.io/squash-benchmark/unstable/?dataset=e...
The hard part is that compression is already an attack vector for the web (e.g., CRIME [2], BREACH [3], et al.). We want to make sure that we're not eroding or unduly complicating that situation [4].
[1] https://tools.ietf.org/html/draft-lee-sdch-spec-00 [2] https://en.wikipedia.org/wiki/CRIME [3] https://en.wikipedia.org/wiki/BREACH [4] https://tools.ietf.org/html/draft-kucherawy-httpbis-dict-sec...
Brotli is naturally limited to 16 MB of memory use whereas ZStd makes less attempts to reduce memory use. If you want to use more memory with Brotli, you need to use another flag '--large_window' instead of '--window', to indicate that you really want it, whereas zstd uses a lot of memory more silently.
When you compare compression levels, you should compare with same memory consumption -- and if you do that, brotli tends to win by 5 %.
When in doubt in benchmarking, run brotli with --large_window 30
https://encode.ru/threads/2947-large-window-brotli-results-a... is a summary of a recent large-scale experiment of a large variety of compressors, including brotli, zstd and LZMA.
Ever heard of flag `--ultra` ? Without it, zstd memory usage will be limited to 8 MB. It has been there since, forever.
What happens if your user data trained dictionary ends up storing user data and you receive a GPDR destruction request?
I wish I knew more about it, but that's what I keep hearing.
This is a resource I've found helpful: https://www3.nd.edu/~pkamat/pdf/graphs.pdf
"Consider readers with color blindness or deficiencies"
"Avoid colors that are difficult to distinguish"
x-axis: compression speed (in input data)
y-axis: compression ratio (1x is no compression).
For more details, here's a comment I made a couple years ago:
There's a nice comparison of compression algorithms (including zlib, zstd, brotli, snappy, etc) here: https://quixdb.github.io/squash-benchmark/ It's nice because it uses many datasets and machine platforms. Unfortunately the graphs leave a bit to be desired, especially when you're trying to compare two algorithms. They provide the raw data, but it needs a little munging to make it workable.
For my day job I made the following graph to compare zlib level1 and zstd. This was using the "peltast" platform which is a Xeon based system, because that was most relevant for us.
(the original comment: https://news.ycombinator.com/item?id=12400503 )
Zstandard outperforms zlib in compression ratio, compression speed, and decompression speed (not shown). The only reason to stick with zlib is for compatibility with systems that expect zlib.
Here's the problem. The graph is designed to make your conclusion sound right, but it doesn't actually prove that.
Let's look at what the numbers really say:
For the sample data, and the best case, gzip gets you a file that's about 31% of the original size. zstandard can get you a file that is 25% of the original size but it will take you four times as long to get it. If you allow it the same time as gzip, you can get 27% compression instead of 31%. That's only 13% improvement on the wire.
That's nice, but it's not impressive at all. It's not a good enough reason to change your stack. The only thing that is impressive is that if you want the same compression ratio as gzip you can do it up to 20 times faster. On some hardware that's totally worth it, but not on all (because who is streaming at 700 MBps?)
It’s just that simple.
For a given compression speed, zstd will compress the file more that zlib would. For a given compression amount, zstd will compress the data much faster than zlib would.
Right now it's impressive "in the middle", but I find myself in a lot of situations where I care about the extremes. I.e. for something that will be transferred a lot, or cold-stored, I want maximum compression, CPU/RAM usage be damned, within reason. So I tend to use LZMA there if files aren't too large. For realtime/network RPC scenarios I want minimum RAM/CPU usage and Pareto-optimality on multi-GbE networks. This is where I use LZ4 (and used to use Snappy/Zippy).
At their scale, though, FB is surely saving many millions of dollars thanks to deploying this, both in human/machine time savings and storage savings.
https://encode.ru/threads/2947-large-window-brotli-results-a...