Imagine a quotation service at an insurance aggregator in Jaipur (an invented firm). The team deploys a new version at 2 p.m. The service starts, passes its health check, and begins taking traffic. For roughly the next ten minutes, response times on the pricing endpoint are three to four times worse than normal. Then, with no change to code or load, they settle. The same thing happens on every deploy. Someone suggests the database is slow. Someone else blames the network. Neither is the culprit. The runtime is.
To see why, we need to take apart a sentence taught in every first course: “a compiler translates the whole program before it runs; an interpreter translates line by line as it runs.” It is not wrong. It is incomplete in ways that matter for exactly this story.
The two textbook ends
At one end is a language like C, C++, Go or Rust. A compiler turns source into machine code for a specific processor and operating system, once, ahead of time. The output runs directly on the CPU. Start-up is fast and speed is steady from the first instruction, but the binary is tied to a platform, and the compiler cannot know how the program will behave on real data.
At the other end is a pure interpreter, which reads the program and acts on it directly. It needs no build step and runs anywhere the interpreter exists, but each operation carries overhead, so it is slower. Early shell scripts and simple Basic dialects worked like this.
What Java and Python actually do
Nearly all popular languages sit in between. The standard Java compiler, javac, does not produce machine code. It produces bytecode, an instruction set for an imaginary processor. That is what “platform independent” means: the same class file runs on any machine that has a JVM (Java Virtual Machine), because each platform’s JVM knows how to execute bytecode. Three names are worth separating. The JVM is the engine that runs bytecode. The JRE is the JVM plus the standard libraries. The JDK is the JRE plus development tools like the compiler. Since Java 11, Oracle and others ship JDKs and no longer a separate JRE download as the main product, though the idea still helps.
CPython, the usual Python, is similar in shape: source is compiled to bytecode (those .pyc files in cache folders), and the interpreter loop executes that bytecode. So “Python is interpreted” and “Python is compiled” are both half true. The label belongs to the implementation, not the language. PyPy runs the same language with a JIT and is often much faster on long-running code.
The JIT: compiling while running
Back to Jaipur. When the JVM starts a service, it begins by interpreting the bytecode, which is quick to get going but slow per operation. While interpreting, it counts how often each method is called and how many times each loop iterates. Methods that turn out to be hot get handed to the just-in-time (JIT) compiler, which translates them into real machine code in the background and swaps it in.
HotSpot, the common JVM, does this in tiers. A fast compiler (C1) produces moderately optimised code early. Methods that stay hot move on to the heavier optimising compiler (C2), which uses the profile it gathered: which branches are really taken, which concrete types appear at a call site. With that knowledge it can inline small methods, remove checks that never fire, and make bets such as “this interface call always lands on this one class”. If a bet is later proved wrong, the JVM discards the optimised code and falls back to slower execution, a step called deoptimisation, then tries again.
This is a real advantage over ahead-of-time compilation, since the optimiser sees the actual workload. The price is warm-up. For the first minutes, the pricing code is running interpreted or lightly optimised while the JIT catches up, and the first requests also pay for class loading. That is the ten-minute slowness. Nothing is broken.
Handling warm-up in practice
- Do not send full traffic to a cold instance. Use gradual ramp-up in the load balancer, or canary a small slice first. Some service meshes and cloud load balancers offer a slow-start setting for this.
- Warm it deliberately. Fire synthetic requests that exercise the hot paths before reporting ready. Use realistic ones; a single “ping” warms almost nothing.
- Watch the memory limits. The JIT itself needs CPU and memory. Containers with a tiny CPU quota make warm-up far slower, because compilation competes with serving requests. Giving a Java container a fraction of one core is a classic cause of long warm-ups.
- Consider ahead-of-time options. GraalVM native image compiles Java to a standalone executable with very fast start-up and low memory, at the cost of build complexity, restricted use of reflection without configuration, and sometimes lower peak throughput. Projects such as CRaC, which restores a pre-warmed snapshot, attack the same problem differently.
For short-lived workloads, such as serverless functions and command-line tools, warm-up never pays back, which is why those environments favour Go, Rust, or native-image Java. For a long-running service that handles millions of requests, the JIT’s peak performance usually beats code compiled blind.
Tidier vocabulary
A more useful question than “compiled or interpreted?” is: when does translation to machine code happen, and what information does the translator have? Ahead of time with no runtime data (C), at start with a profile later (JVM, .NET, V8 for JavaScript), or never, with an interpreter loop (older CPython paths). Each choice trades start-up time, steady-state speed, memory, and portability. Once you read languages that way, the Jaipur graphs stop being a mystery and become a design property you can plan around.
Figures and names in the examples are illustrative.
Leave a Reply