Video in progress
How do you compare AppCDS, CRaC and GraalVM native image for cutting a Java service's startup time?
AppCDS is low risk, a 20-40% gain, and needs no code changes. CRaC restores from a snapshot of a warmed-up process in a fraction of a second, but you have to manage closing and reopening resources. Native image gives millisecond startup and low memory, at the price of a long build, reflection limits, and lower peak throughput without a JIT.
📖 Answer
First the question: why does startup time matter? Scale-up speed, serverless, or just a slow deploy? The solution differs depending on the answer.
AppCDS (Class Data Sharing). It writes the metadata of the loaded classes into an archive and maps it on the next startup. It is convenient in Spring Boot 3.3+:
java -Djarmode=tools -jar app.jar extract --destination app
java -XX:ArchiveClassesAtExit=app.jsa -Dspring.context.exit=onRefresh -jar app/app.jar
java -XX:SharedArchiveFile=app.jsa -jar app/app.jar
The code does not change and there is almost no risk. The gain is moderate. From JDK 24 there is also an AOT cache in this direction (Project Leyden), which prepares even more up front.
CRaC. You checkpoint a warmed-up JVM and restore it later. Startup is 50-100 ms, and the JIT has already done its work. But open sockets, DB connections and files must be closed before the checkpoint and reopened after it. Spring 6.1+ does this for the most part, but you check your own libraries. You need a JDK build that supports CRaC, and extra permissions on Linux. Secrets ending up inside the snapshot is also a security question.
Native image. Startup is 50 ms, RSS is 3-5 times lower. The cost: a build of 5-10 minutes and a lot of RAM; hints for reflection, proxies and resources; some libraries do not work at all; peak throughput is usually below the JIT's (PGO closes the gap); profiling tools are different.
My choice: an ordinary long-lived service gets AppCDS and well-tuned probes. Small functions that scale often get native image. CRaC is for when the others are not enough and the team is ready to support it.
Sign up to mark studied questions and save your progress.