Search code examples
quarkusgraalvmgraalvm-native-image

Quarkus native image size


When I am building a native image of my application with quarkus, I get an executable that has a size of 150MB (the associated jar has a size of 12MB I doubt that Substrate VM make up for all that space). Is this normal or am I doing something wrong ? Is there a way to investigate like logging what is loaded in the native image ?

 $ du -sh target/placeholder-1.0.0-SNAPSHOT-runner                                                                                                                     1.9m  mar. 06 juil. 2021 00:13:58
150M    target/placeholder-1.0.0-SNAPSHOT-runner
 $ du -sh target/placeholder-1.0.0-SNAPSHOT.jar                                                                                                                               mar. 06 juil. 2021 00:14:32
12M     target/placeholder-1.0.0-SNAPSHOT.jar

Solution

  • Yes, the size of the binary can be larger than the jar file. It mostly consists of 2 parts: code of your application compiled to binary and the "image heap" the preinitialized data structures and components of your application. For example, if your application initializes any classes at build time, then the values of the static fields of these classes are serialized into the image heap. This can help startup of the app, because it doesn't need to initialize these again, but it can also make the binary larger.

    There are reporting options you can enable for the native image build process and tools that help you make sense of the contents of the image.

    From the article linked above, you can use the -H:+DashboardAll option and the dashboard tool here (it is hosted on github and works offline): https://www.graalvm.org/docs/tools/dashboard/?ojr=dashboard

    And then it can visualize what takes space for example like this: https://miro.medium.com/max/2400/1*mWIhq53ALPiI2GP-IQkYoQ.png