Skip to content

Commit 0907bb8

Browse files
committed
complete E16
1 parent 73631a6 commit 0907bb8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

NamasteJS/E16.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# [Episode 16](https://www.youtube.com/watch?v=lW_erSjyMeM&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=18): JS Engine EXPOSED 🔥 Google's V8 Architecture 🚀
2+
3+
### JavaScript Runtime Environment
4+
5+
JRE: JS Engine + Web APIs + Callback Queues + Microtask Queues + Event Loop and more interesting things.
6+
7+
There are various JREs. Most common is the Browser.
8+
9+
Node.js is the Runtime Environment that has everything required as a runtime and can be ran outside the browser as well.
10+
11+
### Various JS Engines:
12+
13+
First JS engine developed was SpiderMonkey. SpiderMonkey is the engine used by Mozilla Firefox.
14+
15+
Fastest JS Engine currently is V8. V8 is used by chrome, Node.js and Deno as well.
16+
17+
Other engines are Chakra, Tamarin etc.
18+
19+
### JS Engine:
20+
21+
JS Engine is the heart of JRE.
22+
23+
It executes JS code.
24+
25+
It majorly contains two things: Call Stack and Memory Heap.
26+
27+
It executes the JS code in 3 steps.
28+
29+
1. Parsing: First the JS engine converts the JS code into tokens. Then it converts it into "Abstract Syntax Tree" known as AST. It is basically a syntax parser. Refer [this](https://astexplorer.net/)
30+
31+
2. Compilation: JavaScript has JIT Compilation i.e. Just In Time Compilation. It uses both Interpreter and Compiler for compilation of the code. All JS Engines have own algorithms of compilations. All these JS engine's job is to optimize the code as much as it can.
32+
33+
3. Execution: Memory Heap is space where functions and vars are assigned memory and works in sync with the Call stack. Mark and Sweep Algorithm is famous garbage collector algorithm. Inlining, Copy Elision, Inline Caching etc. are imp compiler concepts.
34+
35+
### V8 Engine
36+
37+
V8 Interpreter: Ignition -> Byte Code
38+
V8 compiler: TurboFan -> Creates Optimized Machine Code -> Byte code
39+
40+
Compiler Optimizes and Interpreter executes.
41+
42+
Garbage collector: Orinoco, Oilpan
43+
44+

0 commit comments

Comments
 (0)