HomeThe ClassicsFarai's Codelab

What The Heck is zstandard (zstd) Compression?

Published:

I used CanIUse.com and I noticed zstd as a new feature called zstandard (zstd). Curious, I decided to read a bit more and it looks like it’s a compression algorithm made by Facebook. It looks like it allows you to increase compression/decompression speeds which keeping similar compression ratios to other algorithms. You can specify a dictionary which is used to guide the compression and decompression, which is useful for smaller files which don’t typically compress well.

I decided to play around with it and compare it with other compression algorithms, specifically gzip and brotli. I was going to use a huge tar archive of raw images, but that took forever so I grabbed all of the markdown files on my computer. That also took forever so I cut it down to 5,000-ish files which was 16MB in total.

I’m too lazy to draw graphs and put the table here, but you can look at the data yourself [CSV 3KB]. Some terrible thoughts that are more for me than you dear reader:

  • Both brotli and zstd have higher compression ratios as well as compression and decompression speeds compared to gzip. Even level 1 of brotli and zstandard are better and faster than max gzip.
  • Brotli seems to have better compression ratios, and for zstd to have similar ratios, it needs the higher compression levels that take much longer to compress.
  • zstd and brotli have similar decompression speeds.
  • brotli is named after a Swiss pastry and zstd isn’t

This analysis is far from perfect (I swear I’m no brotli shill) and I might look into more in the future, but this seemed interesting enough to share. The compression ratios and performance are supposedly better on small files with a trained dictionary (preferably containing redundant data, like API responses) and I didn’t know brotli had a similar feature as well. It’s in the Canary Chrome builds but it looks like WebKit are interested and Firefox are looking into it. I wonder if it would help with image compression? I did compress files as a form of web performance when I still used GitLab Pages. Platforms are better at doing these things nowadays, but I want to try that once I’ve moved in all of my old content.