I wanted to add some data to this discussion. We are talking about the boot process. So I benchmarked the boot time (systemd-analayze time) and the size of the initramfs files for the 5 compression algorithms gzip, xz, lz4, bzip2 and zstd. I used my endeavourOS virtualbox for that. 5 boot process per compression algorithm and I always discarded the slowest result in a series.
bzip2 should not be used. I am taking it out of consideration.
best boot time is with lz4
best compression is with xz
taking out bzip2 the boot time variation is 3-4 %. That is not much.
taking out bzip2 the compression variation is up to 207 %. That is a lot.
For me personally xz is the winner. It boots in 7,78 s. This is just 0,33 s slower than the fastest algorithm lz4. But xz creates the smallest files which are half the size of what lz4 is doing.
We also need to keep in mind that these are really fast boot times because my virtualbox is lean with no extra services. In real life boot times would be longer because of all the service start activities. These extra seconds are more than compensating the performance gain of lz4.
Thanks for the figures and especially for pointing it out it is a VBox.
What hardware did you run this on?
Because obviously if you have a fast Ryzen the differences in time are small.
Try it on a Core 2 Duo and it will look differently - especially with the memory intensive XZ.
One additional thing though: you were measuring the default parameters which are as follows (I leave out bzip2):
EDIT: are you sure that systemd-analyze is the right tool for this? When initram is uncompressed, systemd isnāt loaded yet, AFAIK it only measures time spent in the already uncompressed initram.
But anyways, I tend to believe that the ratios are largely hardware independent. If it is 4 % difference on a fast PC it is most likely 4 % difference on a slow PC as well.
And if you have a slow PC and you start more services in real life, these 4 % difference diminish even further.
And yes, I believe that systemd-analyze time is the right command for that:
systemd-analyze time
This command prints the time spent in the kernel before userspace has been reached, the time spent in the initial RAM disk
(initrd) before normal system userspace has been reached, and the time normal system userspace took to initialize. Note that
these measurements simply measure the time passed up to the point where all system services have been spawned, but not
necessarily until they fully finished initialization or the disk is idle.
But I am open to any suggestion to improve the benchmark. Just let me know how I should measure instead and I will run another test.
I will investigate and report back if I find something.
I donāt believe systemd-analyze is the right command, from your citation:
the time spent in the initial RAM disk (initrd) before
normal system userspace has been reached
So it is already in the initram. But my interpretation can be wrong of course.
While on the decompression side, you might be right, donāt forget compression! XZ is soooo slooooow on old hardware.
And even on this Ryzen 9 I get this:
XZ: mkinitcpio -P with three kernels and four initrams: 75 seconds
ZSTD: 17 seconds.
Thatās almost an entire minute gained!
That is indeed an issue. xz is really slow when compressing. But because compressing is only a one time task during installation of the kernel I did not pay much attention to it. May be I should.
However, your numbers in systemd-analyze appear to be correct.
A manual unpacking of the initram/lz4 takes 0.04 seconds here, whereas xz takes 0.66 seconds.
In a scenario where compression ratio is not relevant, would you say that lz4 is faster than zstd when it comes to both compressing and decompressing? Will the boot time benefit from a faster decompressing?
As these stuff is kind of new to me, at this stage I am experimenting with different options.
Since my previous post, I did actually changed to lz4. I ran a mkinitcpio -P. I didnāt take the time, but it was considerably faster than zstd. Watching the htop as well showed considerable less cpu usage.
Since the size of the compressed images is not of a concern, for now I think I stick with lz4.
Just switched to zstd. I think my system spends more time running mkinitcpio than it does decompressing the initramfs. Hence, on balance, this is a better trade-off for me.