MOK's Onomatomaniske Kaos
Super Cool

Revisiting the zstd compression algorithm


A few days ago, I wrote about various compression algorithms and how they perform. Today, I am looking further into the 19 different compression levels available in zstd. I ran the experiment in exactly the same way, using the same cpio archive and the same computer.

zstd has 19 different compression levels, and in the experiment detailed below they are named “zstd-1”, “zstd-2”, etc. up to “zstd-19”. For purposes of comparison, I have included results from gzip, bzip2 and xz from last time.

The data is detailed is in the table below, but let’s look at it in graphical form. In the graph below, I have plotted the compression time in seconds along the X-axis, and the size of the compressed file in percentage of the initial size along the Y-axis.

The left panel shows all the runs. At the top left the uncompressed file is indicated by a yellow dot at (0, 100). Then in green, all the zstd runs are shown. The result from gzip is shown with a blue dot, bzip2 is magenta dot and xz is a red dot. The compression ratio drops very quickly and then flattens out almost in an L-shape.

In order to show some of the zstd-* results more clearly, the right panel shows a detail of the left panel, as indicated by the grey rectangle.

When advancing from level 1 to 4, zstd delivers increasingly better compression without much cost in terms of run-time. Levels 5-8 do not seem compress any better than level 4, but the execution time increases. The next performance jump comes at level 9 which seems to compress equally efficient to levels 10-16, that all require significantly longer run time. Levels 17-19 delivers a couple of percent better compression, again at the cost of run time.

It seems the default zstd level which is set at 3 is a decent compromise between compression ratio and run time. One could consider using level 4, or perhaps level 9 that seems to stand out.

Screenshot of terminal with fastfetch output

Here’s the data

filealgorithmsize (Mb)% sizetime (s)decomp (s)speed (Mb/s)
archive.cpio1171.3100.00.00.0inf
archive.cpio.gzgzip718.661.356.09.9 (19%)12.8
archive.cpio.zstzstd-1705.360.26.82.9 (43%)103.7
archive.cpio.zstzstd-2688.658.87.13.0 (42%)97.0
archive.cpio.zstzstd-3672.757.49.52.9 (31%)70.8
archive.cpio.zstzstd-4668.557.114.23.1 (22%)47.1
archive.cpio.zstzstd-5670.757.324.93.0 (12%)26.9
archive.cpio.zstzstd-6668.057.026.62.9 (11%)25.1
archive.cpio.zstzstd-7658.556.234.53.0 (9%)19.1
archive.cpio.zstzstd-8656.956.138.63.3 (10%)17.0
archive.cpio.zstzstd-9635.854.350.13.1 (6%)12.7
archive.cpio.zstzstd-10634.654.253.83.3 (6%)11.8
archive.cpio.zstzstd-11634.254.173.23.2 (4%)8.7
archive.cpio.zstzstd-12634.154.175.23.2 (4%)8.4
archive.cpio.zstzstd-13634.254.1152.33.3 (2%)4.1
archive.cpio.zstzstd-14633.954.1137.63.3 (2%)4.6
archive.cpio.zstzstd-15633.454.1159.23.3 (2%)4.0
archive.cpio.zstzstd-16627.953.6207.92.9 (1%)3.0
archive.cpio.zstzstd-17609.552.0300.63.3 (1%)2.0
archive.cpio.zstzstd-18610.752.1379.93.9 (1%)1.6
archive.cpio.zstzstd-19606.151.7476.64.8 (1%)1.3