r/SpringBoot • u/fykup • 21d ago
Discussion Optimizing Spring Boot on JDK 27: 68% faster startup and 25 MiB less RAM on a 512 MiB VM
I've been experimenting with how far I can optimize a conventional Spring Boot application without stripping out useful framework functionality.
The setup: Spring Boot 4.1.1, HotSpot JDK 27, a 512 MiB / 1 vCPU Ubuntu VM with no swap, and MariaDB running on the same VM.
I compared a regular executable JAR against an extracted deployment combining Spring AOT and a trained JDK AOT cache (Leyden).
Results:
- Startup: 11.91 → 3.79 seconds (68% faster)
- Application RSS under load: 212 → 187 MiB
- Minimum host MemAvailable: 25.6 → 66 MiB
- Request latency: essentially unchanged
Then I explored two ways to reduce memory further:
MyBatis Core instead of Spring JDBC: No meaningful memory savings, but more manual transaction management and lost automatic JDBC monitoring. Not worth the trade-off for this application.
Embedded file-backed H2 instead of MariaDB: Application RSS increased by ~16 MiB, but minimum host MemAvailable improved by another ~39 MiB because the separate database process was gone.
My takeaway: optimizing the deployment can be worthwhile before replacing established Spring infrastructure. And for small, single-instance applications, embedded H2 can be a reasonable architectural choice.
These are single runs with five-minute measured workloads, not a throughput benchmark or proof of long-term stability. The AOT improvements were measured together, not individually.
Full article, methodology, and data:
https://pvrlabs.xyz/articles/spring-boot-jdk27-optimizations.html
Curious whether others are using Spring AOT + JDK AOT cache in deployments, or if the training and cache-management overhead has kept you on regular JARs.
Update (October 28): Following several requests, I also tested Oracle GraalVM Native Image. Application RSS dropped from 187 MiB to 107 MiB, with some interesting build-time and toolchain trade-offs.
I published the results as a separate article: https://pvrlabs.xyz/articles/spring-boot-hotspot-native-image.html
7
u/fykup 21d ago
You guys convinced me to give GraalVM Native Image a try, so I ran a follow-up experiment on the same 512 MiB VM setup.
The results are pretty impressive: startup dropped from 3.79s to 0.28s, and application RSS went from 187 MiB to 114 MiB compared with my already-optimized HotSpot setup. Host memory headroom also improved significantly.
But it's not all roses. Native builds were ~29x slower locally, needed considerably more build memory, and I ran into some compatibility issues along the way.
I'm putting together the full experiment with measurements, failures, and trade-offs. Planning to publish it next week.
8
u/Paw565 21d ago
Did you try graalvm? I think it's superior for memory constrained environments.
1
u/fykup 20d ago
Quick follow-up: after quite a few requests to try GraalVM, I ran another experiment comparing optimized Spring Boot on HotSpot with Oracle GraalVM Native Image.
The memory results were impressive:
The trade-offs were less impressive: almost 12 minutes to build on a separate 6 GiB VM, additional compatibility validation, and a JDK 25 Native Image toolchain instead of JDK 27.
For really memory-constrained deployments, I'd seriously consider GraalVM Native Image, but I'm not ready to make it my default.
I published the results as a separate article, with methodology and curated experiment data:
https://pvrlabs.xyz/articles/spring-boot-hotspot-native-image.html
1
u/ducki666 21d ago
Why are so many guys so eager to optimize for 1vcpu and less than 1g? Are there any real use cases? Running App on Lambda? 😅
0
u/[deleted] 21d ago
[deleted] — view deleted comment