Class Data Sharing (CDS) and Layered Jar to Improve Runtime Efficiency
Key point
A MyBatis-based Spring Boot app reduced its initial startup time by 30% using CDS and Layered Jar.
Details
Approaches like GraalVM Native Image, Project CRaC, and Project Leyden have been proposed to reduce Java applications' weak point, initial startup time. Among these, native image has a big effect but comes with many constraints, and CRaC has a high barrier to adoption due to its Linux dependency and troubleshooting burden.
In this case, Application Class-Data Sharing (CDS), which Project Leyden will leverage, was applied first to reduce the startup time of a system that includes MyBatis. The development environment was JDK 21, Spring Boot 3.2.2, and MyBatis 3.0.3, taking advantage of Spring Framework 6.1.3's official support for CDS.
The application procedure was to first create an archive with -XX:ArchiveClassesAtExit=application.jsa, then run the application specifying -XX:SharedArchiveFile=application.jsa. Log analysis showed that out of a total of 18,034 classes and JDK proxies, 81.25% were loaded from the cache, with the org.springframework family accounting for a large portion.
Layered Jar, used together with CDS, is a method that leverages Spring Boot's layer structure to reduce duplication in Docker images. By separating and copying the dependencies, loader, snapshot dependencies, and application layers in a multi-stage Dockerfile, you can minimize the scope of changes while improving image management and execution efficiency.
The actual result was a reduction in initial execution time from 83 seconds to 56 seconds. This is about a 30% improvement—smaller than GraalVM's effect, but presented as a viable alternative worth considering in environments where applying the more complex native image approach is difficult.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.