GraalVM Native Image biên dịch Java sang machine code ahead-of-time (AOT) — không cần JVM lúc chạy.
Lợi ích:
- Startup ~100ms (vs 4+ giây trên JVM).
- Memory giảm 50%+.
- Tiết kiệm chi phí serverless (Lambda, Cloud Run — billing theo ms).
- Kubernetes pod start nhanh, scale-to-zero hiệu quả.
Spring Boot 3+ tích hợp AOT engine — pre-compute bean metadata lúc build.
Thách thức:
- Reflection invisible với static analysis — Jackson, Hibernate cần reflection hint.
- Dynamic proxies phải khai báo trước.
- Classpath scanning không chạy runtime.
- Build time chậm (10-20 phút) so với JVM bundle (vài giây).
- JIT warmup không còn → peak performance đôi khi thấp hơn JVM warmed-up.
Giải pháp: Spring AOT processor tự generate hint cho hầu hết case. Thư viện third-party đôi khi cần config thủ công (reflect-config.json, @RegisterReflectionForBinding).
Khi dùng: function ngắn (Lambda), CLI tool, microservice cần scale-to-zero nhanh. Không phù hợp app chạy lâu cần JIT peak performance.
GraalVM Native Image compiles Java to ahead-of-time (AOT) machine code — no JVM needed at runtime.
Benefits:
- Startup ~100ms (vs 4+ seconds on the JVM).
- 50%+ less memory.
- Lower serverless costs (Lambda, Cloud Run — billed per ms).
- Fast Kubernetes pod startup, efficient scale-to-zero.
Spring Boot 3+ includes an AOT engine that pre-computes bean metadata at build time.
Challenges:
- Reflection is invisible to static analysis — Jackson, Hibernate need reflection hints.
- Dynamic proxies must be declared upfront.
- Classpath scanning does not work at runtime.
- Build times are slow (10-20 minutes) compared to JVM bundles (seconds).
- No JIT warmup → peak performance is sometimes lower than a warmed-up JVM.
Solution: the Spring AOT processor generates hints for most cases. Third-party libraries occasionally need manual configuration (reflect-config.json, @RegisterReflectionForBinding).
When to use: short-lived functions (Lambda), CLI tools, microservices needing fast scale-to-zero. Not ideal for long-running apps that benefit from JIT peak performance.