- Parser: Itchecks for syntax and semantics. Parser is nothing but a lexical analysis that results into the breaking of code into tokens in order to understand their meanings and these tokens gets converted into Abstract Syntax Tree(AST).
- Abstract Syntax tree: It is a hierarchical tree like structure of program representation which allows interpreter to understand the program. This AST is initially goes to the Interpreter.
- Interpeter: It lets the AST to get converted into Byte code. In V8 engine, this process is known as Ignition but when some code gets repeated again and again.
// Arrow function
const multiply = (a, b)=> a*b;
In the above code, we are calling multiply() function 1000 times. When this code goes into the interpreter, the interpreter performance got decreased, since, Interpreter had to repeat this code again and again and then profiler will mark this code as warm and comes into action.
- Profiler: It will check for the repeating code that can be optimized. As soon as, it gets the repeating code, it basically moves the code into compiler.
The Spider Monkey converts the main JS code into the byte code through the compiler, after that the byte code goes into two section Interpreter and JIT Compiler.
Mozilla’s SpiderMonkey Engine three things are important which are as follows:
- IonMonkey JIT Compiler: It is mainly used for optimization of code.
- Garbage collector: It is used for claiming the memory used by objects that are no longer used by the program. The GC is a mark-and-sweep, non-conservative collector. It is used to hold the JS objects and the string descriptors.
Chrome’s V8 Engine -> 98%
Mozilla’s SpiderMonkey -> 87%