How does the V8 Engine actually work?
Working of V8 Engine
1. Parsing Phase
Parsing is the process of analyzing the source code, checking it for errors, and breaking it up into parts.
2. AST Conversion
The parser produces a data structure called the Abstract Syntax Tree or AST. AST is a tree graph of the source code. It does not show every detail of the original syntax but contains structural details.
Example of AST
You can play with the AST here
An interpreter executes each line of code line by line, without requiring them to be compiled into a machine language program. Interpreters can use different strategies to increase performance. They can parse the source code and execute it immediately, translate it into more efficient machine code, execute precompiled code made by a compiler, or some combination of these. In the V8 engine, the interpreter outputs bytecode.
In modern engines, the interpreter starts reading the code line by line while the profiler watches for frequently used code and flags then passes it to the compiler to be optimized.
5. Compilation Phase
The compiler works ahead of time to convert instructions into a machine-code or lower-level form so that they can be executed by a computer. It runs all of the code and tries to figure out what the code does and then compiles it down into another language that is easier for the computer to read.
That's it, folks! hope it was a good read for you. Thank you! ✨
👉 Follow me: Github Twitter LinkedIn Youtube
Did you find this article valuable?
Support Rehan Sattar by becoming a sponsor. Any amount is appreciated!