Comparing Native Image Size of Java ,Spring Boot, Quarkus and Micronaut
In this blog post we will look at the native image size of Java, Java based frameworks Spring Boot, Quarkus and Micronaut.
Based on the below tweet, I became curious to know the bare minimum size of a native application for Java and Java based frameworks.
Code Used in Native Images
I am trying to use simple class or Rest API to compare image sizes.
Java – A class which prints “Hello World”
Spring Boot, Quarkus, Microanut – Rest API which responds with “Hello World”
Hardware
I am using GitHub Action to build the native images. For x86 architecture, I have used the hardware hosted by GitHub and for ARM64 architecture I have used self hosted runners.
X86
Hardware specification for Windows and Linux virtual machines:
- 2-core CPU (x86_64)
- 7 GB of RAM
- 14 GB of SSD space
Hardware specification for macOS virtual machines:
- 3-core CPU (x86_64)
- 14 GB of RAM
- 14 GB of SSD space
ARM64
Hardware specification for Linux virtual machines:
- 1-core CPU ( ARM64 )
- 4 GB of RAM
- 40 GB of Hard disk Space
Note : I am using Oracle Cloud ampere (Arm64) processor
Hardware specification for Mac OS :
- 8-core CPU (ARM64)
- 16 GB of RAM
- 500 GB of SSD space
Java
OS | Size (MB) | Build Time |
Windows (x86) | 11.2 | 2m 38s |
Linux (x86) | 11.4 | 1m 39s |
Mac (x86) | 11.1 | 3m 10s |
Linux (ARM64) | 11.5 | 2m 41s |
Mac (ARM64) | 11.3 | 38s |
Repo : https://github.com/sureshgadupu/java-native-image
Native Images : https://github.com/sureshgadupu/java-native-image/releases/tag/0.0.1
Spring Boot
OS | Size (MB) | Build Time |
Windows (x86) | 67.8 | 7m 8s |
Linux (x86) | 70.5 | 5m 15s |
Mac (x86) | 67.2 | 6m 1s |
Linux (ARM64) | 70.8 | 8m 54s |
Mac (ARM64) | 68 | 1m 44s |
Repo : https://github.com/sureshgadupu/sb3-native-image
Native Images : https://github.com/sureshgadupu/sb3-native-image/releases/tag/0.1.5
Quarkus
OS | Size (MB) | Build Time |
Windows (x86) | 41 | 7m 31s |
Linux (x86) | 41.4 | 3m 43s |
Mac (x86) | 40.5 | 6m 52s |
Linux (ARM64) | 41.5 | 7m 40s |
Mac (ARM64) | 41 | 1m 21s |
Repo : https://github.com/sureshgadupu/quarkus-native-image
Native Images: https://github.com/sureshgadupu/quarkus-native-image/releases/tag/0.0.9
Micronaut
OS | Size (MB) | Build Time |
Windows (x86) | 55.8 | 6m 32s |
Linux (x86) | 60.1 | 3m 52s |
Mac (x86) | 55.2 | 7m 41s |
Linux (ARM64) | 60.4 | 8m 14s |
Mac (ARM64) | 56 | 2m 2s |
Repo : https://github.com/sureshgadupu/micronaut-native-image
Native Images : https://github.com/sureshgadupu/micronaut-native-image/releases/tag/0.0.5
Size
- Java native image size is only around 12MB
- Quarkus has the lowest size (Around 42 MB) while Spring Boot has the largest size (around 71 MB) , Micronaut sitting in the middle.
- Micronaut has highest image size difference ( around 5 MB) among different architectures.
Build Time
While we can not compare build times for across different architectures of single framework as we are using different hardware specification we could compare across different frameworks as they were built using same spec’d hardware.
Spring Boot | Quarkus | Micronaut | |
Windows (x86) | 7m 8s | 7m 31s | 6m 32s |
Linux (x86) | 5m 15s | 3m 43s | 3m 52s |
Mac (x86) | 6m 1s | 6m 52s | 7m 41s |
Linux (ARM64) | 8m 54s | 7m 40s | 8m 14s |
Mac (ARM64) | 1m 44s | 1m 21s | 2m 2s |
Quarkus build time is lowest for Linux (x86), Linux (ARM64), Mac (ARM64) while Spring Boot claims for Mac (x86) and Micronaut for Windows (x86)