AOT vs JIT Compilation in Java — Startup, Throughput, Memory, and Build Trade-offs
Fast recall
Quick revision
Core answer
Whether you understand the deep trade-off between profile-guided runtime optimization (JIT) and the predictability of build-time compilation (AOT)
Assuming AOT is always better because 'sub-100ms startup' (it isn't — peak throughput is often lower; reflection configuration is a real burden; build complexity increases significantly)
Explain how Tiered Compilation works in HotSpot (C1 → C2), how PGO closes some of the throughput gap for AOT, and when CRaC offers a middle path
Interview-ready guide
Interview answer
JIT and AOT optimize for different lifecycles, and the right choice depends on whether your workload values startup latency or peak throughput.
JIT compilation (HotSpot's default):
- Starts by interpreting bytecode — immediate but slow
- Profiles at runtime — gathers data on hot methods, taken branches, observed receivers
- Compiles hot methods via Tiered Compilation — C1 for fast-compiled lightly-optimized code, C2 for aggressively-optimized code using profile data
- Result: highest peak throughput, but 3-8 second startup and 30-60 second warmup
AOT compilation (GraalVM Native Image):
- Compiles the entire application at build time using closed-world analysis
- Sub-100ms startup, 30-50% lower memory footprint
- No runtime adaptation — must make optimization decisions from static analysis alone
- Peak throughput typically 10-30% lower than fully-warm JIT
- Requires explicit reflection configuration
Why JIT achieves higher peak throughput:
- C2 makes speculative optimizations like inlining virtual calls based on observed receivers
- If speculation turns out wrong, the JVM deoptimizes and recompiles — adaptive
- AOT cannot do this; everything must be decided once, at build time
The middle ground — CRaC:
- Snapshots a fully-warm JIT-compiled JVM and restores in under a second
- Preserves JIT's peak throughput while achieving AOT-like startup
- Trade-off: in-memory state is captured; secrets and connections need refresh on restore
When to choose each:
- JIT: long-running services, CPU-bound workloads, dynamic behavior (reflection, hot redeploy)
- AOT: serverless functions, CLI tools, autoscaling environments where pods come and go
- CRaC: when you want fast cold starts but cannot accept native image's throughput penalty
Honest trade-offs of AOT:
- 5-15 minute builds vs 30-second JAR builds
- Reflection burden — every reflectively-accessed class needs configuration
- Library ecosystem — most work, some don't
- Debugging is harder than JIT-compiled JVM
Pragmatic decision rule:
- Start with JIT — Spring Boot 3 with AppCDS is fast enough for most use cases
- Switch to AOT when measurement shows startup is materially affecting UX or cost
In an interview, the differentiator is mentioning Tiered Compilation and PGO — most candidates know AOT is faster to start; few understand WHY JIT achieves higher peak throughput.
AOT vs JIT Compilation in Java — Startup, Throughput, Memory, and Build Trade-offs
Direct Answer
JIT compilation (HotSpot's default) interprets bytecode initially, then compiles hot methods to optimized native code at runtime using profile data. It produces excellent peak throughput but has slow startup (3-8 seconds for Spring Boot) and a warmup period during which performance ramps up. AOT compilation (GraalVM native-image, Project Leyden) compiles the entire application to native code at build time. It delivers sub-100ms startup and 30-50% lower memory footprint but typically lower peak throughput (no profile-guided runtime optimization) and requires explicit reflection configuration. The right choice depends on whether your workload values startup latency (serverless, CLI tools, scaling) or peak throughput (long-running services, batch processing).
Common Mistakes & Pitfalls
Assuming AOT is always better because 'sub-100ms startup' (it isn't — peak throughput is often lower; reflection configuration is a real burden; build complexity increases significantly)
Check your understanding
Answer these without looking back at the article.
- What is Tiered Compilation in HotSpot and how does it work?
- How does Profile-Guided Optimization (PGO) close the throughput gap for AOT?
- When is CRaC the right choice over both JIT and AOT?
- What library ecosystem limitations exist for GraalVM Native Image in 2026?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.