Monday, November 28, 2022

36/365: V8 Engine

 Speed is everything on the web. This constant pursuit of greater speed pushed Google to create their V8 Javascript engine. The V8 engine is a just in time (JIT) compiler. It constantly alternates between compiling the code and running it, and as it runs the code more it becomes more efficient with the compilation. This achieves a massive speed up in Javascript, but how does V8 achieve this? First the V8 parser reads the source code and creates an abstract syntax tree. Next, the interpreter named Ignition consumes the abstract syntax true to produce bytecode. This bytecode is ran, and as runtime information is collected as the code is recompiled. If as the code runs it is found certain functions are "hot", meaning they are being called frequently. these functions are passed to the optimizing compiler Turbofan. Turbofan them along with other information gathered at runtime to compile the Javascript to even faster machine code. This process also involves various "speculations" created by the compilers, which are tested in pursuit of the fastest bytecode. V8 itself is written in C++. 

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...