Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Follow publication

Secret Behind JavaScript Performance: V8 & Hidden Classes

Chameera Dulanga
Bits and Pieces
Published in
7 min readAug 5, 2021

--

None of these is possible without the invention of the V8 JavaScript Engine.

Build in AI speed — Compose enterprise-grade applications, features, and components
Build in AI speed — Compose enterprise-grade applications, features, and components

What is V8 & How It Works

The most significant difference between V8 and other engines is its Just In Time (JIT) compiler.

High-level architecture of V8 engine

But, we all know that compilers are much faster than interpreters. So then why V8 engine uses an interpreter instead of a compiler?

Tip: Build applications differently

An independently source-controlled and shared “card” component (on the right, its dependency graph, auto-generated by Bit)

Abstract Syntax Tree

// Function declaration
function addition(x, y){
var answer = x + y;
console.log(answer);
}
// Calling the function
addition(10,20);
{
“type”: “Program”,
“body”: [
{
“type”: “FunctionDeclaration”,
“id”: {
“type”: “Identifier”,
“name”: “addition”
},
“params”: [
{
“type”: “Identifier”,
“name”: “x”
},
{
“type”: “Identifier”,
“name”: “y”
}
],
“body”: {
“type”: “BlockStatement”,
“body”: [
... ],
“kind”: “var”
},
... “sourceType”: “script”
}

Hidden Classes to Optimize JavaScript Code

Changing object attributes on the fly

V8 engines use hidden classes to overcome this issue and optimize the JavaScript execution.

How Hidden Classes Work

This hidden class concept not only allows you to bypass dictionary lookups; it also allows you to reuse already created classes when similar objects are created or modified.

Writing High-Performing JavaScript Code

Conclusion

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Written by Chameera Dulanga

Associate Technical Lead | AWS Community Builder (x4) | Content Manager

Responses (4)

Write a response