Blogs


The V8 chrome engine

 May 12, 2021, 02:37 PM

 3 min read

chrome
v8
engine
chromium
browser
nodejs
compiler

In my previous blog, I have mentioned that under the hood of nodejs, the V8 chrome engine is being used. But what is the V8 chrome engine?

V8 is a JavaScript engine which can run standalone, or be embedded into any C++ application. It compiles JavaScript to machine code before executing it, handles memory allocation for objects, and garbage collects objects it no longer needs. This departure from traditional techniques allows JavaScript to run much faster, which improves users’ experience of the web, paves the way for the development of web applications, and spurs rapid growth of server-side JavaScript through projects like Node.js.
Source: Google developers

Beneath the hood
In essence, it compiles ASCII text javascript code to machine readable binary codes and executes it. However, contrary to traditional approaches, the engine does not compile the entire javascript code in advance. It does something called a just in time (JIT) compilation. Basically, the engine compiles the code at run time and executes it. It is incredibly fast and powerful due to how much it is optimized from the previous generations of javascript engines. It is thanks to this v8 engine that we can run javascript outside the browser making mobile and desktop application development, databases, microservices, backend and server side rendering ever more feasible.

Optimizing performance
The V8 engine is written in C++, which is one of the fastest language ever, making the engine incredibly performant. It is portable and runs on Windows, MacOS, Linux and other operating systems. JavaScript is generally considered an interpreted language, but modern JavaScript engines no longer just interpret JavaScript, they compile it.
Sandboxing is one of the key features shipped with the V8 engine. It runs javascript functions in an isolated environment much like how you would want to conduct chemical experiments in an isolated environment in order to get the most optimal results with the least tempered environment. This ensures that functions which are ran separately do not affect each other. This isolation of javascript processes does not result in a performance decline.


The V8 engine was developed by the chromium project, which is used for the Google chrome browser. The iconic functions of the V8 engine makes it a pioneer in the modern era of javascript development.


Arafat

Mohammad Arafat Zaman

"Technophile"


Go back

Mohammad Arafat Zaman © 2024


All rights reserved