2.0 - V8 Pipeline
References
- An Introduction to Speculative Optimization in V8 [Benedikt Meurer]
- Ignition - an interpreter for V8 [Ross McIlroy] (slides)
- V8 pipeline [eternalsakura]
0. Compiler pipeline
Source: JavaScript Start-up Performance by Addy Osmani
Take the following function for example,
function add(x, y) {
return x + y;
}
for (var i = 0; i < 1000000; ++i) {
add(1, 2);
}
add("hello", "world");
The add
function was called so many times that V8 marks it as “hot”. So Turbofan will come in to optimize this function and produce machine code. Since add
has only been called with smi arguments, Turbofan can produce machine code that only works for small integers.
Later, add("hello", "world")
was called. Now the arguments are no longer smis, hence the assumption that the arguments are smis is invalid, and so V8 will deoptimize and fall back to bytecode.