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.
In more detail
Because JavaScript is dynamically typed, a compiler cannot know types in advance. V8 gathers type feedback while interpreting, and TurboFan uses it to produce fast code for the common case.
Related terms
- TurboFan — V8's optimising compiler, which turns hot functions into fast machine code based on the types it has seen.
- 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.
- dynamic typing — A language design where a variable can hold a value of any type and types are only checked while the program runs.
Taught in
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services