Snap deltas are OK but not great

A quick update on this, in the context of snapcraft’s support for LZO compression (https://snapcraft.io/blog/why-lzo-was-chosen-as-the-new-compression-method). While LZO compression does produce larger snap files - i.e. the compression ratio is not as high as it is with XZ - it seems that there may be a benefit in terms of delta sizes.

Prompted by @picchietti in another thread I experimented with deltas on SquashFS images created with different compression methods. The image was of a minimal OS file tree with a Python application, where a single character was added to a file. So it’s basically a large image with a minimal change.

I should say this was completely non-scientific. The mksquashfs options are also not exactly what snapcraft uses (I kept most defaults), and I used default compression levels for all compression types. But the results are quite interesting!

For each of the compression types supported by mksquashfs - as well as the case where I simply put the OS tree in a tar archive without compression - the image and delta sizes are as follows:

+--------------------+----------------+----------------+
| Compression method | Image size (B) | Delta size (B) |
+--------------------+----------------+----------------+
| none (tar)         |    132,444,160 |         91,700 |
| lz4                |     67,796,992 |          8,236 |
| lzo                |     51,961,856 |          8,829 |
| gzip               |     46,866,432 |        148,645 |
| lzma               |     36,757,504 |        117,643 |
| xz                 |     36,737,024 |        117,019 |
+--------------------+----------------+----------------+

As we expect, the LZO image size is far from the smallest; the archive is 41% larger than the XZ-compressed one. But the delta size is 13x smaller than the XZ delta.

The LZO delta is smaller than any of the other methods - even the uncompressed archive - by at least an order of magnitude. The only compression that yields a smaller delta (by a whisker) is LZ4, at the expense of an archive that’s 30% larger than LZO.

Again, this was sort of an artificial test case that may not be representative, but it looks like switching compression might yield some significant benefits here. At some point I’ll try to do some tests with real-life snaps using LZO.

4 Likes