v8: a Tale of Two Compilers

Ever wanted to take a peek under the hood of v8, Google’s Javascript virtual machine, without having to check out the code and poke around?

Here is a nice post that gives a look at what’s going on behind the scenes:

V8 compiles all JavaScript to native code. V8 has two compilers: one that runs fast and produces generic code, and one that doesn’t run as fast but does try to produce optimized code.

The quick-and-simple compiler is known internally as the “full-codegen” compiler. It takes as its input the abstract syntax tree (AST) of a function, walks over the nodes in the AST, and emits calls to a macroassembler directly.