v8 JavaScript engine

The V8 JavaScript Engine : A high-performance JavaScript engine

In this V8 introduction, we will ignore the implementation details of V8: they can be found on more authoritative sites (e.g. the V8 official site), and they change over time, often radically.

What is V8 javascript engine?

V8 JavaScript engine was initially developed for Google Chrome and Chromium web browsers to improve the performance of JavaScript execution. The project’s creator, Lars Bak, created the first version that was released at the same time as the first version of Google Chrome in September 2008. The engine was initially designed solely for execution by web browsers, but the latest versions also execute JS code outside of the browser, enabling server-side scripting.

Other JS engines

Other browsers have their own JavaScript engine:

and many others exist as well.

A high-performance JavaScript engine

V8 is written in C++, and it’s continuously improved. It is portable and runs on Mac, Windows, Linux and several other systems.

This might seem counter-intuitive, but since the introduction of Google Maps in 2004, JavaScript has evolved from a language that was generally executing a few dozens of lines of code to complete applications with thousands to hundreds of thousands of lines running in the browser.

Our applications now can run for hours inside a browser, rather than being just a few form validation rules or simple scripts.

Compilation

  • JavaScript is generally considered an interpreted language, but modern JavaScript engines no longer just interpret JavaScript, they compile it.
  • This has been happening since 2009, when the SpiderMonkey JavaScript compiler was added to Firefox 3.5, and everyone followed this idea.
  • JavaScript is internally compiled by V8 with just-in-time(JIT) compilation to speed up the execution.

How V8 JavaScript Engine Works

When a developer runs a JS script on V8, the following steps are taken by the engine:

  • The engine compiles and executes the JS code
  • The engine handles the call stack
  • The engine manages the memory heap
  • The engine handles the garbage collection
  • The engine provides all the data types, objects and functions
  • The engine also provides the event loop (sometimes implemented by the browser as well)

Key Notes:

  • V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and Node.js, among others.
  • It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.
  • V8 can run standalone, or can be embedded into any C++ application.
  • V8 is the name of the JavaScript engine that powers Google Chrome. It’s the thing that takes our JavaScript and executes it while browsing with Chrome.
  • V8 provides the runtime environment in which JavaScript executes. The DOM, and the other Web Platform APIs are provided by the browser.
  • The cool thing is that the JavaScript engine is independent of the browser in which it’s hosted. This key feature enabled the rise of Node.js.
  • V8 was chosen to be the engine that powered Node.js back in 2009, and as the popularity of Node.js exploded, V8 became the engine that now powers an incredible amount of server-side code written in JavaScript.

 Conclusions:

On the web, there is a race for performance that’s been going on for years, and we (as users and developers) benefit a lot from this competition because we get faster and more optimized machines year after year. V8 provides the runtime environment in which JavaScript executes. The DOM and the other Web Platform APIs are provided by the browser.

V8 is always evolving, just like the other JavaScript engines around, to speed up the Web and the Node.js ecosystem.