What’s inside the Google V8 Engine?

google
javascript

#1

JavaScript has always been an interesting language fro the developers across the globe for its user-friendliness. We thought that by knowing how the building blocks of JavaScript play together and write better code and applications. There are many JavaScript engines which are committed to the clarification and depiction of the numerous pages. Among all, it is the Google V8 Javascript engine which has become the talk of the town these days. People are going gaga over its functionalities and flexibility.

Basically, a Javascript engine resembles a program or an interpreter which executes the javascript code. It can be implemented as a standard interpreter or a compiler just-in-time that compiles JavaScript to bytecode in some other form. Here is the list of popular projects that are implementing a Javascript engine:

  • Chakra — Internet Explorer for JScript9 and Microsoft Edge for JavaScript

  • JerryScript — A lightweight engine for the Internet of Things.

  • JavaScriptCore — Developed by Apple for Safari and open source, marketed as Nitro

  • KJS — KDE’s engine for the KDE project’s Konqueror web browser

  • Nashorn — Open source as part of OpenJDK which is written by Oracle Java Languages and Tool Group

  • Rhino — Open source, developed entirely in Java

  • SpiderMonkey — The first JavaScript engine, which back in the days powered Netscape Navigator, managed by the Mozilla Foundation, and today powers Firefox

  • V8 — Developed by Google which is an Open source and written in C++

What makes V8 engine so popular?

Google built the V8 engine which is an open source, written in C++ and can be used inside the Google chrome. It is more popular unlike the rest of the engines for the Node.js runtime. V8 was developed for increased performance of Javascript execution inside the web browsers. V8 engine translates the Javascript code into more efficient machine code without the need of a compiler to obtain the speed.

The V8 engine has two compilers namely full-codegen and crankshaft which help for the thread management by translating the JavaScript abstract syntax tree to a high level static single assignment (SSA) called Hydrogen and tries to optimize Hydrogen graph.

Inlining

The first optimization is inlining which is the process of replacing a call site with the body of the called function and inlining the code in advance. The given picture demonstrates the process.

image

Hidden Class

There are no classes and objects created using a cloning process in the Javascript and hence it provides a dynamic programming language which means that properties can be easily added or removed from an object after its instantiation. V8 uses the method of the hidden class to find the location of object properties in the memory and work similarly to the fixed object layouts and classes used in languages like java.

Inline Caching

Another technique for optimizing dynamically types languages in V8 is termed as inline caching. IT relies on the observation that the repeated calls to the same method tend to occur on the same type of the object. Inline caching is important because of the objects of the same type are hidden classes and you create two objects of the same type and with different hidden classes, V8 won’t be able to use inline caching because of the different properties.

Ignition and TurboFan

An execution pipe was introduced in the earlier version of the V8 engine. This achieves even bigger performance improvements and significant memory savings in real-world Javascript applications. On the top of Ignition is the new execution pipeline for v8’s interpreter and newest optimizing compiler TurboFan. The new pipelines pave the way for further optimizations that boosts JavaScript performance and shrink footprints of V8 in both Chrome and Node.js in the upcoming years.

Before You Go

Finally, this means that the overall V8 will have much simpler and more maintainable architecture going forward. Google is also making effort for more progress and growth in the V8 engine; also released some exciting and new featured guide to what is a V8 engine in general along with its application.