Taco Steemers

A personal blog.
☼ / ☾

Factors in deciding which jlink compression level to use

jlink is the Java equivalent of a linker . It can be used to bundle your code and dependencies with a Java Runtime Environment.

With the use of jlink it becomes easier to deploy an application to a customer because we don't need the customer to manually install the correct Java runtime environment. jlink comes with a few options for reducing the output size.

Here we look at the --compress option. It has three options: 0: no compression, 1: constant string sharing and 2: ZIP. I think the numbers indicate how much time they cost during the execution of jlink, with option 2 taking the most time.

According to this bug report the ZIP option can lead to a 13 millisecond slower startup time on a Hello World program. Personally I am okay with small startup delays for the graphical desktop application I am working on.

What concerns me more is installer size and size on disk. I will show an example based on a private project I am working on. Here I used the excellent InnoSetup for creating the installer, but the general idea will apply to any installer or packaging system that applies compression to reduce the total package size.

jlink compression level InnoSetup Installer size Size on disk Size on disk compared to installer size
Level 0: No compression 21.864.448 bytes 97.210.368 bytes ~4.5 times increase
Level 1: Constant string sharing 21.835.776 bytes 77.504.512 bytes ~3.6 times increase
Level 2: ZIP 36.855.808 bytes 61.747.200 bytes ~1.7 times increase

As we can see the installer size will be bigger when we use the most compression. I believe that this is because the components that have been compressed by jlink cannot be compressed much further and might reduce the potential for compression among the other files. It can also be that InnoSetup uses a more efficient compression method.

Conclusion

To conclude, there are four factors we can take in to account when deciding which jlink compression level we want to use.

  • Package or installer size. Use level 1 if you want a smaller package size. It will still benefit the size on disk after installation.
  • Size on disk. Use level 2 to get the smallest disk usage after installation. Note that more bytes will need to stored and transferred by the software distribution system.
  • jlink execution speed. Choose level 0 if you want the fastest jlink execution speed.
  • Application startup time. Choose level 0 if you want the fastest application startup.