To learn about JavaScript engines is to learn about JavaScript under the hood, basically what goes on when you run your code. A proper understanding of this topic would help you write much better code. This guide to JavaScript engines will help you to understand JavaScript engine performance and some of their most important features.
JavaScript engines are programs that convert JavaScript code into lower level or machine code.
JavaScript engines follow the ECMAScript Standards. These standards define how the JavaScript engine should work and what features it should have.
In general, higher level languages like JavaScript, C, FORTRAN are abstracted from machine language. JavaScript is much farther abstracted from machine level than C/C++. C/C++ are in comparison much closer to the hardware among other reasons making them much faster than other high-level languages.
Compilation and Interpretation are some general approaches used in code implementation by programming languages.
A compiler is a program that transforms a computer code written in a programming language (source language) into another programming language (target language). They translate a source code from a high-level programming language to a lower level language e.g machine code.
An interpreter goes through your source code statement by statement and executes the corresponding machine code directly on the target machine.
An interpreter directly executes (performs instructions written in a programming language).
While interpretation and compilation are the two of the principles by which programming languages are generally implemented, they are not totally unrelated, as most interpreting systems also perform some translation work, just like compilers.
JavaScript is usually categorized as interpreted although it is technically compiled. Modern JavaScript compilers actually perform Just-in-time Compilation which occurs during run-time.
JavaScript engines are embedded in browsers and web servers, such as Node.js to allow run-time compilation and execution of JavaScript code.
Google V8
Google’s V8: It is an open-source JavaScript engine that was developed by The Chromium Project for Google Chrome and Chromium web browsers. The project’s creator is Lars Bak. The first version of the Chrome’s V8 engine was released at the same time as the first version of Chrome: September 2, 2008. It has also been used in server-side technologies like Node.js and MongoDB.
This engine has the Ignition Interpreter used for interpreting and executing low-level bytecodes. Bytecodes, although slower, are smaller than machine codes and requires lesser compilation time. Full-Codegen is a compiler that runs fast and also produces unoptimized code. The Crankshaft is a slower compiler that produces fast, optimized code. TurboFan, the JIT compiler will profile the code and see if it is used multiple times throughout the entire JavaScript execution. The garbage collector will find objects and data that are no longer referenced and collect them. The V8 engine stops program execution when performing a garbage collection cycle.
V8’s compilation pipeline with Ignition enabled.
CHAKRA: There is the chakra (JScript engine) but for the purpose of this article I would be talking briefly on the chakra (JavaScript engine). Chakra is a JavaScript engine developed by Microsoft for its Microsoft Edge web browser. It is a fork of the JScript engine used in Internet Explorer. Chakra in a general sense changes the execution qualities of JavaScript inside Internet Explorer 9. Chakra contains a new JavaScript compiler that compiles JavaScript source code into high-quality native machine code, a new interpreter for executing the script on traditional web pages, and improvements to the JavaScript runtime and libraries.
Block diagram of Chakra’s design.
SPIDERMONKEY: It is the code name for the first JavaScript engine, written by Brendan Eich at Netscape Communications, later released as open source and currently maintained by the Mozilla Foundation SpiderMonkey written in C and C++. It is used in various Mozilla products, including Firefox, and is available under the MPL2 (Mozilla public license version 2.0). SpiderMonkey integrates type inference with Jaegermonkey, JITcompiler to generate efficient code. SpiderMonkey contains an interpreter, several JIT compilers (TraceMonkey, JägerMonkey, and IonMonkey), a decompiler, and a garbage collector.
RHINO: This JavaScript engine was written fully in Java and managed by the Mozilla Foundation as open source software. It is separated from the SpiderMonkey engine, which is also developed by Mozilla, but written in C++ and used in Mozilla Firefox.
NASHORN: For more information on this, check this link
https://docs.oracle.com/javase/10/nashorn/introduction.htm
JERRYSCRIPT: For more information on this, check this link http://jerryscript.net/
github repository: https://github.com/jerryscript-project/jerryscript
KJS: Github repository https://api.kde.org/frameworks/kjs/html/index.html
Benchmark measures the execution of a JavaScript engine through running code that is used as a part of the modern web applications. Benchmark results may not be 100% exact and may likewise vary from platform to platform or devices. To perform a test, check out https://arewefastyet.com/
In the most basic terms, JavaScript engines take your source code, splits it up into strings or lexes it, takes those strings and changes over them into bytecode that a compiler can understand, and afterward executes it. The objective of a JavaScript engines’ code parsing and execution process is to produce the most optimized code in the shortest conceivable time. web developers should know about the distinct characteristics in the browsers that show the code that we work so difficult to create, debug, and maintain. Why certain scripts work slowly on one program, yet more rapidly on another. Mobile web developers need to understand the restrictions inherent to and possibilities offered by the different browsers on their devices. Staying aware of the progressions in JavaScript engines will truly pay off as you advance as a web, mobile, or application developer.
Leave a Reply
Your email address will not be published. Required fields are marked *