Quick revision
The short answer
Because HotSpot compiles from run-time profiles and deoptimises when its guesses break, Java performance is not fully deterministic: it depends on what the code has seen, so a new traffic mix or feature can cause short regressions while the JIT adapts. A company should therefore express guarantees as statistical SLOs on latency percentiles, measured continuously in production, and protect them with continuous performance tests on realistic traffic, warmup gates and canaries for every JDK and code change. AOT caches with stored profiles reduce warmup variance, and where hard real-time guarantees are truly needed, we choose architectures or technologies built for them.
What to remember
In this answer, we saw that HotSpot's speculation and deoptimisation make performance depend on run-time history, so traffic changes, new features and fresh instances cause short regressions. The strategy that follows is to promise statistical SLOs on percentiles measured continuously in production, to guard them with replay-based performance tests, warmup gates and canaries for every JDK and code change, to use AOT caches with stored profiles to narrow warmup variance, and to use purpose-built technology where hard real-time guarantees are required.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Because HotSpot compiles from run-time profiles and deoptimises when its guesses break, Java performance is not fully deterministic: it depends on what the code has seen, so a new traffic mix or feature can cause short regressions while the JIT adapts. A company should therefore express guarantees as statistical SLOs on latency percentiles, measured continuously in production, and protect them with continuous performance tests on realistic traffic, warmup gates and canaries for every JDK and code change. AOT caches with stored profiles reduce warmup variance, and where hard real-time guarantees are truly needed, we choose architectures or technologies built for them.
Why this question is asked
Latency-critical systems, such as payments, trading or ad bidding, often come with promises to customers or regulators. If we promise a number that the runtime cannot guarantee by its nature, we either break the promise or overspend to hide the variance. Interviewers ask this at the principal or director level to see whether we can translate a property of the JVM into an engineering and contractual strategy that lasts for years. In this answer, we will recap why JIT performance depends on history, look at what that means for guarantees, define the SLO model, describe the testing and rollout discipline, and see where AOT caches and other technologies fit.
1A Quick Recap: Performance That Depends on History
HotSpot does not compile a method once and for all. It profiles the code while it runs, then C2 compiles the hot parts using that profile: it inlines the receiver types it has seen, compiles never-taken branches as traps, and relies on the classes loaded so far. When reality changes, a new branch is taken or a new type appears, the JVM deoptimises that code, runs it more slowly for a while, and recompiles. A freshly started process also has no profile at all, so it starts slow and gets faster.
So the speed of the same code on the same machine depends on what that process has seen: how long it has run, the mix of requests, which features are enabled. That is the source of both Java's excellent peak performance and its variance.
2What This Means for Guarantees
Three kinds of events produce short regressions even when nothing is wrong. Startup and scale-out add cold instances. A change in traffic mix, for example a new customer whose requests use different code paths, shifts profiles. A new feature or a flag flip triggers deoptimisation and recompilation. Each typically lasts seconds to minutes, and each affects a fraction of requests.
A guarantee such as no request ever takes longer than 5 ms is therefore not something a JIT-based system can honestly promise, independent of how well it is tuned; GC pauses and the operating system add their own variance. What we can promise, and measure, is a statement about the distribution: the share of requests that meet a target over a window.
3Statistical SLOs, Measured Continuously
We define SLOs, service level objectives, as percentiles over time windows. For example, 99.9 percent of requests complete within 20 ms, measured over 28 days, with a separate objective for p99 per five-minute window to catch short bad periods. The SLO is backed by an error budget, the allowed share of requests that miss, which gives us a number to spend on deploys and experiments.
These SLOs are measured continuously in production, not in a lab, because only production has the real traffic mix. Latency histograms per instance, tagged with JDK version, build and instance age, let us see whether misses cluster in fresh instances, after deploys or after flag flips, which tells us which part of the process to improve.
| Statement | Honest for HotSpot? | Why |
|---|---|---|
| Every request under 5 ms | no | warmup, deopt and GC create rare outliers |
| p99.9 under 20 ms over 28 days | yes | statistical, measured in production |
| p99 under 10 ms per 5-minute window | yes, with gates | needs warmup gating and canaries |
| Bounded worst case, provably | no | needs real-time systems by design |
4Continuous Performance Testing and Safe Rollouts
Since performance depends on behaviour, the tests must reproduce behaviour. We run continuous performance tests with realistic traffic, ideally recorded production requests replayed at production rates, long enough to include warmup and steady state, for every significant code change and every JDK update. A regression in p99 or CPU per request fails the pipeline the same way a functional bug does.
Production changes go through warmup gates and canaries. A new instance reports ready only after a warmup phase with representative requests. A new build or JDK first runs on a few instances with real traffic, and its latency histogram is compared with the current version before rollout continues. Feature flags are enabled for a small percentage first, so the JVM adapts to new paths while most traffic still runs on optimised code.
- Code or JDK changeincluding minor JDK updates
- Replay-based performance testwarmup and steady state, p99 and CPU
- Within budget?Yesbuild a canaryNofix before release
- Canary instances with warmup gatecompare histograms to current version
- Canary within SLO?Yesgradual rolloutNoroll back, investigate
5 steps in order. Play them, or step through them one at a time.
5AOT Caches and Warmup Variance
A large part of the variance comes from cold processes. Project Leyden's AOT cache attacks exactly that: since JDK 24 it stores loaded and linked classes from a training run, and since JDK 25 it can store method profiles too, so a new instance starts with knowledge of what the code usually does and the JIT can compile hot methods sooner. That narrows the startup tail, but it does not remove adaptation to new behaviour after startup, so the testing and canary discipline stays.
6When to Choose Something Else
Some requirements really are hard: a control loop that must respond within 1 ms every time, or a system whose certification demands a proven worst-case bound. For those, the honest answer is a different design rather than more tuning. Options include isolating the hard real-time part into a component built for it, using a real-time Java implementation or another language and runtime designed for bounded latency, or architectures that do not depend on the slow path, such as hedged requests that send a duplicate after a deadline. The rest of the system can stay on standard Java, where its strengths matter more than determinism.
7Follow-up questions
How do you explain this to a business stakeholder?
I would say that our system is fast almost all the time, and that we measure and promise how often it is fast, for example 999 of every 1,000 requests within 20 ms. Promising every request is not something any general-purpose runtime can honestly do. Then I show the SLO dashboard and the error budget, which makes the promise concrete and checkable.
Would native image remove the variance?
It removes JIT warmup and deoptimisation, so startup is fast and behaviour is more predictable from the first request. But native image code has no run-time profiling, so peak throughput is often lower unless profile-guided optimisation is used, and GC still causes some variance. For some latency-critical services that trade is worth it; for many it is not.
What do you track to see if the strategy works?
SLO attainment and error budget burn per service, latency tails split by instance age and by change events, time to steady state for new instances, and the number of regressions caught by performance tests versus in production. If regressions keep reaching production, the test traffic is not realistic enough.
8Conclusion
In this answer, we saw that HotSpot's speculation and deoptimisation make performance depend on run-time history, so traffic changes, new features and fresh instances cause short regressions. The strategy that follows is to promise statistical SLOs on percentiles measured continuously in production, to guard them with replay-based performance tests, warmup gates and canaries for every JDK and code change, to use AOT caches with stored profiles to narrow warmup variance, and to use purpose-built technology where hard real-time guarantees are required.
Open with
The key point is that HotSpot's performance depends on what the process has seen. The JIT profiles the code, compiles speculatively, and deoptimises and recompiles when reality changes, and a new process starts with no profile at all.
Then, if they want more
So a new traffic mix, a new feature or a flag flip, and every new instance can cause short regressions even when nothing is wrong. For a company with latency-critical systems, that means we should not promise that every request is under a fixed number, because the runtime cannot guarantee it.
Instead we set statistical SLOs on percentiles, for example 99.9 percent under 20 milliseconds over 28 days plus a p99 per five-minute window, and measure them continuously in production, split by instance age and change events so we can see where misses come from.
We protect those SLOs with continuous performance tests using replayed production traffic, including warmup, for every code and JDK change, with readiness gates that require warmup, and with canaries that compare latency histograms before rollout. AOT caches in recent JDKs can store profiles from a training run, which reduces startup variance.
And where the requirement is truly hard real-time, I would isolate that part and use a technology built for bounded latency rather than tuning harder.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 24, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "HotSpot's JIT relies on speculation and deoptimisation, so performance depends on...": https://scrivio-interview-library.netlify.app/java/jit-compilation/ce3280f6e3/