V8 Javascript Engine

Saimeghanakamineni
4 min readJul 19, 2020

--

Before going into V8 JavaScript engine. Let’s have a quick overview of the Javascript engine.

What is Javascript engine?

JavaScript engine is nothing but a program/interpreter that converts Javascript code into a lower level or machine code that microprocessors can understand.

JavaScript was initially created as a browser-only language but is now used in many other environments such as front-end(angular, react.js,vue.js etc) and backend scripting(node.js).

Javascript Engine

What is V8 JavaScript Engine?

V8 is an open-source JavaScript and Web Assembly engine developed by google which converts JavaScript code to machine code.

V8 Javascript Engine

V8 is written in C++ and is independent of the browser. It is portable and runs on Mac, Windows, Linux, and several other systems. V8 Javascript engine was created by Lars Bak and his team. The first version of V8 launched alongside the first version of Google chrome on September 2, 2008.

The engine was initially designed solely for execution by web browsers, but the latest versions also execute JS code outside of the browser (i.e.., server-side), enabling server-side scripting (Nodejs).

Purpose:

V8 was designed to increase the performance of JavaScript execution inside web browsers. V8 JavaScript was developed for google chrome and chromium web browsers to improve JavaScript execution.

Why V8 Javascript engine is considered one of the fastest JS engines?

V8 JavaScript engine is a combination of Interpreter and Compiler named as Just in Time compiler (JIT). Just in Time (JIT) compiler compiles JavaScript code to native machine code. JIT compiler optimizes code during runtime which makes execution faster.

Just in Time compilation is implemented is other JS engines such as Spider Monkey or Rhino etc. But the main difference is V8 doesn’t produce any intermediate code saving time.

Key components of V8:

Key components in V8 JS engine

1) Ignition:

The V8 JS engine has an interpreter named “Ignition”. This interpreter is used for interpreting and executing low-level bytecode.

Ignition Interpreter

2) Liftoff:

Liftoff is a web assembly that generates machine code and performs its tasks in a highly optimized manner. It was introduced in the latest version of V8 for WebAssembly-based apps and modern browsers

Liftoff

3) TurboFan:

TurboFan is a powerful compiler with a graph-based intermediate representation (IR) suitable for advanced optimizations (strength reduction, inlining, code motion, instruction combining, and sophisticated register allocation).

TurboFan

5) Orinoco:

Orinoco is for garbage collection. Its job is to look for disconnected memory allocations and perform evacuation and compaction to free up space for more objects.

Orinoco garbage collector

How Javascript engine works:

V8 parses our source code and generates an abstract syntax tree. After that, Ignition (the V8 interpreter) generates bytecode from this syntax tree so that the compiler will understand. V8 consists of an optimized compiler that converts bytecode to machine code. The next process is the execution of the code and handling garbage collection.

Inside V8 JS engine

V8 javascript engine is one of the main reasons behind google chrome’s speed and smoothness(Fastest and mostly used browser in the world)in delivering outputs.

Applications of V8:

  1. Chromium-based web browsers, Google Chrome
  2. Node.js runtime environment
  3. NativeScript mobile application framework
  4. Electron desktop application framework, used by the Atom and Visual Studio Code text editors

--

--