deoptimization
When a just-in-time compiler throws away optimised machine code because the assumptions it was built on no longer hold, and falls back to slower code.
In more detail
Optimised code assumes things seen so far, such as the types of values, will stay true. When one turns out false, the runtime must undo the optimisation, and frequent deoptimization wastes time recompiling.
Example
In V8, passing an object of a new shape, or a string where a number was always seen, sends TurboFan code back to Ignition bytecode; node --trace-deopt shows it happening.Related terms
- JIT compiler — A compiler inside a runtime that turns intermediate code into native machine code while the program runs.
- JVM warm-up — The first period of a Java program's life, while classes load and hot methods are still being compiled, when it runs slower than it will later.
- TurboFan — V8's optimising compiler, which turns hot functions into fast machine code based on the types it has seen.
- speculative optimization — Compiling code on the bet that values will keep the types seen so far, with checks that fall back to slower code if the bet fails.
- hidden class — An internal record V8 keeps of an object's property names and their order, so it can find properties quickly.
- --trace-opt and --trace-deopt — V8 command-line flags that make Node.js print a line each time a function is optimised or deoptimised, with the reason.
Taught in
- The Lifecycle Of A Java Program — Modern Java: Virtual Threads & High-Throughput Services
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services