Which initramfs compression is best? Fastest?
I realized I don’t know, so I made a little benchmark to check.
The factors which are important to me are actual compression time, decompression time at boot, and file size.
I have a few different machines I can use for testing, but since this only really matters on the desktop and the laptop, I just tested on those two.
I used the initramfs for the machine for testing compression times and file sizes, and started qemu with the OS kernel to check decompression times. Compression and decompression happened on tmpfs, so I don’t measure disk speed.
Here are the results:
Desktop PC, i7-12700:
Method | Compression | Decompression | Ratio |
---|---|---|---|
cat | 0.021 | 0.451203 | 1.000 |
zstd | 0.056 | 0.483197 | 2.867 |
gzip | 1.730 | 0.549631 | 2.847 |
bzip2 | 2.709 | 1.326491 | 2.998 |
lzma | 14.278 | 1.146223 | 3.779 |
xz | 6.787 | 0.918145 | 3.749 |
lzop | 0.139 | 0.480965 | 2.074 |
lz4 | 0.118 | 0.437618 | 2.018 |
Laptop PC, i7-1195G7 @ 2.90GHz
Method | Compression | Decompression | Ratio |
---|---|---|---|
cat | 0.033 | 1.003908 | 1.000 |
zstd | 0.143 | 1.084584 | 2.655 |
gzip | 3.569 | 1.238887 | 2.629 |
bzip2 | 5.126 | 3.155971 | 2.754 |
lzma | 37.298 | 2.882291 | 3.375 |
xz | 19.613 | 1.943340 | 3.371 |
lzop | 0.237 | 1.045240 | 1.976 |
lz4 | 0.189 | 1.076398 | 1.925 |
Looks like my desktop is way faster than the laptop, and lzma is by far the worst on both, followed by bzip2.
xz compressed boots just a bit slower than gzip, and has a really good compression ratio, but since I typically reboot only for kernel upgrades, the compression time is too much for me, expecially on the laptop.
zstd and lz4 are for me the clear winners, and gzip is still really good, only slightly worse than zstd on decompression, but much slower on compressing.
I think I’ll go with zstd for now.