GraalVM Native Image compile Java app thành native executable — không cần JVM lúc chạy. Build bằng native-maven-plugin: mvn -Pnative native:compile (cần GraalVM) hoặc mvn -Pnative spring-boot:build-image (native Docker image, không cần cài GraalVM).
| JVM | Native | |
|---|---|---|
| Startup | ~2-5s | ~50-200ms |
| Memory (RSS) | ~300MB | ~50-80MB |
| Throughput | Cao (JIT) | Thấp hơn ~10-20% |
| Build time | ~30s | 3-10 phút |
Cơ chế — AOT: Spring Boot 3 phân tích app lúc build, sinh reflection metadata; Native Image compile thành binary. Closed-world: mọi code phải biết trước lúc compile.
Hạn chế: reflection phải khai báo (thư viện ngoài đôi khi cần reflect-config.json); dynamic proxy/CGLIB giới hạn; classpath scanning không chạy runtime; build chậm.
Dùng khi: serverless/AWS Lambda (cold start), CLI (Spring Shell), microservice cần startup nhanh + memory thấp. KHÔNG dùng khi: cần throughput cao (native kém JIT ~10-20% sau warmup), dùng nhiều lib chưa hỗ trợ GraalVM, team chưa quen debug native.