V8 Engine
Last updated
Last updated
Written in C++
by Googgle.
Used to transform Javascript to bytecode so that the machine can execute.
Javascript
-> C/C++
.
C++
-> Assembly
.
Used in browsers, nodejs, Deno and others.
V8 traditional way is to compile the code in two phases (Ignition & Turbofan
).
First phase the code is transformed into machine code. This process is fast BUT not optimal.
It is enough to get started.
More detailed steps are:
V8 parses the source code and turns it into an Abstract Syntax Tree (AST)
, along with scopes
.
Based on the AST
and scopes
, the Ignition
interpreter can produce bytecode.
At this point, the engine starts running the code and collecting type feedback.
The second phase start at the same time as the first one, but it is a slower process as it produces more optimized code.
Once the slow compilation finishes, Javascript switches to that optimal compiled code.
To make it run faster, the byte code can be sent to the optimizing compiler along with feedback data. The optimizing compiler makes certain assumptions based on it and then produces highly-optimized machine code. This happens in parallel and V8 marks frequently used bytecodes as “hot” codes and converts it into more efficient machine code.
A newer aproach created for the compilation process.