Home > front end >  Native Image Size is atleast twice the actual Jar size
Native Image Size is atleast twice the actual Jar size

Time:12-31

Have built a native-image using Spring Boot 3.0.1 and GraalVM 22.3.0. The built native-image size is atleast twice as that of the original application jar.

I'm with the understanding if unused classes are removed as part of the native-image build process, it should be lesser in size.

CodePudding user response:

If you look closer to the documentation you will understand

A GraalVM Native Image is a complete, platform-specific executable. You do not need to ship a Java Virtual Machine in order to run a native image.

So a GraalVm Native Image, contains both the application and the dependencies needed for this container to execute. Without Native image you normally had as JAR just the application and the embedded tomcat. You did not had inside this JAR the JRE or JDK, required to run the JAR file.

The above could also be verified from graalVm.

Native Image is a technology to compile Java code ahead-of-time to a binary – a native executable. A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.

The language runntime in case for java and jdk are normally between 100mb - 200mb. The graalVm probably reduces this size but not in huge size. So the native executable image is increased by even 1 hundred Mbs just from that.

  • Related