From the previous chapter, we learned that since JavaScript is translated into intermediate code every time it is executed, a higher-performance interpreter must be available to parse JS as it becomes more and more complex. 1. The origin of V8 scripting engine. 2. Evolution of the V8 scripting engine. 3. V8 core module: parser, interpreter, optimized compiler.
Evolution of V8 scripting engine
The first version of V8 was released in 2008, with much more performance than its contemporary competitors (SpiderMonkey, JavaScriptCore) and a lot of attention.
The V8 architecture was aggressive at the time, compiling JavaScript code directly into machine code and executing it, so execution was fast, but V8 only had Codegen as a compiler and code optimization was limited.
So, in 2010, V8 released the Crankshaft compiler, where JavaScript functions were typically compiled by full-codeGen and recompiled with their Crankshaft if the function was later executed multiple times, producing more optimized code that was then executed with optimized code. Further improve performance.
However, Crankshaft optimizations to the code were limited, so TurboFan was added to V8 2015.
At this point, however, V8 was still an architecture that compiled source code directly into machine code, which had a core problem: memory consumption. On mobile devices in particular, full-CodeGen compiles almost a third of Chrome’s machine code, leaving even less memory for code to run.
So the Ignition interpreter was added to the V8 in 2016, reintroducing bytecode in an effort to reduce memory usage.
In 2017, V8 released a new build pipeline, which uses a combination of Ignition and TurboFan to compile and execute code, starting with V8 5.9. The earlier full-CodeGen and Crankshaft compilers were no longer used to execute JavaScript.
Among them, the most core is three modules:
Parser
Interpreter (Ignition)
Optimized Compiler (TurboFan)
In the next chapter, we will learn how to execute JavaScript code in V8 by parsing, interpreting, and compiling.
If this article can help or inspire you, it will be my pleasure