How Javascript Engine’s Work?

?????????? ?????? is a program that executes the javascript code. These days relevant modern engines use just-in-time compilation for improved performance. (As per Wikipedia)

????????? ????? ?? ?????????? ?????? ???????? ??? (Generic for any JS Eng…


This content originally appeared on DEV Community and was authored by varunprashar5

?????????? ?????? is a program that executes the javascript code. These days relevant modern engines use just-in-time compilation for improved performance. (As per Wikipedia)

javascript engine

????????? ????? ?? ?????????? ?????? ???????? ??? (Generic for any JS Engine):

  1. Javascript source code is passed to "Parser"

  2. Parser divides the code into multiple tokens

  3. It is converted into AST (Abstract Syntax Tree), a tree-like structure that represents functions, conditionals, scopes etc.

  4. This AST is passed to the interpreter which converts the code into Bytecode.

  5. At the same time engine is actually running the Javascript code

  6. Bytecode is used by optimizing compiler along with profiling data

  7. "Optimizing compiler" make certain assumptions based on profiling data and produces highly optimized machine code.

Sometimes there is a case where the 'optimization' assumption is incorrect and then it goes back to the previous version via the "Deoptimize" phase (where it actually becomes the overhead to us)

JS Engine usually optimizes "hot functions" and uses inline caching techniques to optimize the code.

???'? ??? ????? ?? ??:

  1. Interpreter is called "Ignition".
  2. Optimizing compiler is called "TurboFan".
  3. Apart from Parser, there is a "pre-parser" that checks for syntax and tokens

? ?????? ?????? ?? ??: "Sparkplug" is introduced which is present between "Ignition" & "TurboFan" which is also called Fast Compiler.

????: These are high-level step's that most of the JS engines goes through and every engine goes through their own set of steps for further optimizations.

They do have stack, heap, garbage collector and is out of scope for this post.

Do share more about JS engines in the comments

Checkout my youtube channel for more such content:
https://www.youtube.com/channel/UCJErruzdazYFQfDdb6avbtA


This content originally appeared on DEV Community and was authored by varunprashar5


Print Share Comment Cite Upload Translate Updates
APA

varunprashar5 | Sciencx (2021-06-29T07:29:03+00:00) How Javascript Engine’s Work?. Retrieved from https://www.scien.cx/2021/06/29/how-javascript-engines-work/

MLA
" » How Javascript Engine’s Work?." varunprashar5 | Sciencx - Tuesday June 29, 2021, https://www.scien.cx/2021/06/29/how-javascript-engines-work/
HARVARD
varunprashar5 | Sciencx Tuesday June 29, 2021 » How Javascript Engine’s Work?., viewed ,<https://www.scien.cx/2021/06/29/how-javascript-engines-work/>
VANCOUVER
varunprashar5 | Sciencx - » How Javascript Engine’s Work?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/29/how-javascript-engines-work/
CHICAGO
" » How Javascript Engine’s Work?." varunprashar5 | Sciencx - Accessed . https://www.scien.cx/2021/06/29/how-javascript-engines-work/
IEEE
" » How Javascript Engine’s Work?." varunprashar5 | Sciencx [Online]. Available: https://www.scien.cx/2021/06/29/how-javascript-engines-work/. [Accessed: ]
rf:citation
» How Javascript Engine’s Work? | varunprashar5 | Sciencx | https://www.scien.cx/2021/06/29/how-javascript-engines-work/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.