JavaScript - JIT Compilation
History of JS:
What's called JS?
Compiler:?
The compiler collects and converts all the code into machine code. And execute in a single shot. Before implementing it’ll generate an Executable file. It’s used in languages like C, C++, and JAVA.
Pros:
Cons:
Interpreter:
The interpreter is fast, it translates the source code line by line and executes it immediately line by line.
Pros:
Cons:
Entry of Super Hero:
JS is an interpreted language, it uses an interpreter in the browser for language conversion. However, interpreters have some performance inefficiency. interpreters don't have any optimization logic. If we are running one loop in JS, every loop goes via an interpreter.?
To overcome this, we need one add-on. I.e JIT.
JIT:
It’s a Hybrid Execution Model. This is a technique used in dynamic programming languages like JavaScript, Python, and Java.
JIT compilation is the combination of both Interpreter and compiler to improve the optimization and runtime performance. This hybrid compilation system balances prompt code execution and performance in code execution patterns.
Parsing and Lexing:
?Profiling:
Before the code execution, the JS engine collects all data about the code such as usage of code, frequently called functions, and code which affects the performance. This is called Profiling. And also it helps the compiler and interpreter to understand the run time behavior of code.
Monitor:
This system tracks the code execution, memory usage, CPU consumption, and benchmarks. And helps to identify the performance bottlenecks.
Profiling and Optimization:
?? The code has been sectioned based on profiling and monitoring, like
Optimization decision:
Optimization- JIT Compilation:
Store and Execution:
Dynamic Adaptation:
Based on run time code checks, Dynamic Adaptations will continuously monitor the optimization strategies to improve efficiency.
Runtime Feedback:
?Runtime feedback provides insights into how the program executes during the final execution. Such as code paths, and resource usage patterns.
Reoptimization and Deoptimization:
So the JS engine orchestrates the code execution decision with the help of runtime feedback data, static analysis,? continuous monitoring, and profiling.
?I’m wrapping up. Thanks, everyone for joining me on this journey through the world of? JS JIT Engines. And if any mistakes were made, please feel free to correct me- It’s all part of learning.
Let's keep Exploring Together.