NewsCrawler.org

Every scenario that triggers V8's "slow mode" for objects

Every scenario that triggers V8's "slow mode" for objects
Every scenario that triggers V8's "slow mode" for objects
Every scenario that triggers V8's "slow mode" for objects
Every scenario that triggers V8's "slow mode" for objects
Image: Reddit

The article explains how V8, the JavaScript engine, stores object properties internally. V8 describes the shape of each object with a hidden class[1], which it calls a Map internally, and objects with the same structure can share one hidden class. When a property is added, the object moves to another hidden class, and the author says this works because data often follows repeating patterns, which keeps property locations predictable.

An inline cache[2] remembers, for each place in the code that reads a property, the expected hidden class and a direct load operation, so repeated accesses skip the lookups. Without a cached result, V8 must find the Map, then the entry in its descriptor array, then the value's offset.

When properties are constantly added and removed, the hidden class approach becomes less efficient, and V8 may switch to dictionary mode[3]. In this mode, properties are stored in a hash table[4] that maps names to values and attributes. The article breaks off before it describes the costs of this mode and how to avoid it.

Repository V8 github.com

V8 is Google's open source, high-performance JavaScript and WebAssembly engine, written in C++.

Stars: 25,340Forks: 4,360License: NOASSERTIONUpdated:

Product V8 v8.dev

V8 is Google's open source, high-performance JavaScript and WebAssembly engine, written in C++.

Read the original yuval.hashnode.devDiscussion

Discussion

Commenters question the list of deletion cases, asking why deleting a property is split into several scenarios. Another asks whether V8 ever switches an object back to fast mode, for example in hot loops. One commenter asks for a table of the first transition for assignment and defineProperty on Node 22, 24 and 26, to track the 20 vs. 1021 split across releases.

Sources

Published: First seen: Читать по-русски

Open as a page