Skip to main content

When JavaScript's V8 switches your Object to "slow mode".

and how to avoid it.

Updated 12 min readMarkdown
When JavaScript's V8 switches your Object to "slow mode".

Objects are the main data-storage structure in JavaScript. Inspired in part by the work of David Ungar, creator of the late-1980s programming language: Self, JavaScript's creator and designer, Brendan Eich, made Objects fundamental to the language, both abstractly and semantically, as well as technically, at the low-level, "under-the-hood" implementation level.

Essentially, almost EVERYTHING in JavaScript revolves around objects. Even primitives support object-like property access (though this involves temporarily wrapping certain primitive values in their corresponding object types, a process known as "boxing"). It is said that Eich originally intended primitives to behave more like full-fledged objects, but treating them as such internally would sacrifice many of the optimizations that modern runtimes can apply to primitive values.

A Recap of Objects

Objects, are key:value structures with dot notation access (someObject.someKey); A key:value pair is called a Property. Properties has two parts: a name (Property Name), and a **value (**Property Value), e.g.:
name: "Yuval".

This is a straightforward and elegant way to represent data, just as the language was designed to be.

But, of course, there are other necessary components that make data usable and interpretable at a lower level, most importantly, its data type, which essentially tells the system how to interpret a value.

JavaScript is a dynamically typed language, meaning that values carry their types at runtime rather than requiring explicit, fixed type declarations. The engine determines how to represent and handle those values, and may also maintain additional type or representation information for optimization purposes.

There are other kinds of metadata associated with properties. Some of these are exposed through JavaScript's high-level interface as Property Descriptors. They determine aspects of a property's behavior, such as whether it is writable, enumerable, configurable, and more.\

These characteristics are also represented in V8's low-level object-storage machinery, in a surprisingly similar way.

Dynamic Data Shapes Come at a Price

The advantages of key:value structures with dynamic typing and dynamic, non-strict data shapes (schemas) are obvious: they are quick to work with, straightforward, flexible, and easy to develop with.

They abstract away almost EVERYTHING that CAN be abstracted away, while still providing the answers to two essential questions about any data item:

  • "What does this value represent?".
  • "What is its value?"

But this comes at a price, a trade-off. The lack of a predictable shape inevitably introduces overhead, particularly in the form of additional lookups.

Hash Tables

One of the best-known data structures for efficiently resolving string-based keys is the Hash Table. To quickly recap its design principles:

String keys are transformed into numerical hash values using a hash function. These values are then used to locate entries in an underlying storage structure, often an array of buckets.

A common approach is to apply an additional modulo operation to the hash value, using the array's capacity, to determine the appropriate bucket index. Of course, collisions must also be handled, since different keys can produce the same bucket index.

This approach introduces overhead: computing or retrieving the hash, locating the bucket, and potentially resolving collisions.

One of the best-known challenges of hash tables is that they typically rely on an underlying storage structure with a finite capacity. When the table grows, it may need to be resized, potentially requiring entries to be redistributed.

Therefore, the relationship between a key's hash value and its actual storage index is not necessarily stable.

This doesn't mean hash values themselves cannot be cached, but it means that a particular bucket index cannot always be treated as a permanent memory offset.

These considerations, among others, help explain why V8 engineers actually opted to use another optimization strategy for ordinary JavaScript objects.

Enter: "Hidden Classes"

One of the key mechanisms behind JavaScript object storage in V8 is something nicknamed "Hidden Classes". Internally, V8 calls them Maps.

Each JavaScript object references a Map describing its current structure. Importantly, multiple objects with the same structure can share the same Map.

The Map contains low-level structural metadata, including, normally, a reference to a Descriptor Array; This array describes the named properties associated with that structure, including information about how and where their values are stored.

For properties stored as fields, the descriptor can identify a direct memory offset index - where the raw value is actually stored (by default on a JSObject representation itself, sometimes on a separate Properties storage when the number of properties is too high.

Essentially, the optimization is based on the assumption that even a so called "dynamic data structure" such a JavaScript object, is often, in practice, "not that dynamic", and that the nature of data itself it to follow familiar or repeating "patterns". An assumption that frequently turns out to be true.

When the structure changes, for example, when a new property is added, V8 may transition the object to another hidden class. These transitions can form a branching network of known object shapes, with common structures reused by multiple objects.
The result is that property locations can become predictable, even in a language whose object structures are inherently dynamic.

Inline Cache (IC)

An Inline Cache (IC) is a runtime optimization mechanism that remembers information about operations performed at particular locations in executable code.

For property access, this typically means associating a cache with a specific property-access, such as person.age, rather than simply caching values globally or once per function.

This allows repeated executions of the same operation to become considerably faster.

When JavaScript code accesses a property for the first time, and no suitable cached lookup information is available, V8 may need to resolve it through the object's structure:

A. Read the object's reference to its current hidden class (Map).
B. Find the property in the Map's Descriptor Array.
C. Determine whether the value is stored directly within the JSObject or in its separate properties storage, and identify its offset.
D. Retrieve the actual value.

There are several different look-ups involved here.
But once the operation has been resolved, the engine can record useful feedback for subsequent accesses, that essentially caches two things to the IC:

  • The expected hidden class (Map), used to verify that the object has the anticipated shape.
  • A specialized load operation, which retrieves the property directly from its known storage location.

This is a huge optimization that directly skips the previous look-ups.

"Dictionary Mode"

Remember the part about hash tables?
Remember the part about hidden classes?
Remember how we described V8 creating and reusing hidden classes for different object shapes?
And remember that this optimization is based on the assumption that objects tend to have a relatively manageable number of recurring shapes?

Well, what if they don't?

What if an object has properties that are constantly being added and removed?

At some point, maintaining fast-property layouts and their associated structural metadata can become less efficient than using a different representation.

This is where V8 may switch to what is known as "Dictionary Mode".

The interesting part is that V8's alternative representation actually DOES use a hash-table-based structure.

Instead of using the fast-property layout, the object stores its named properties in a dictionary that associates property names with their values and attributes.
This representation makes frequent additions and deletions more practical, but it sacrifices some of the optimizations available to fast properties.
In particular, V8 generally cannot use the same direct-offset inline-cache optimizations for dictionary properties.

Instead, accesses involve dictionary-aware lookup mechanisms, which are typically slower than directly loading a field from a known offset.

The two representations have aptly been named:

"Fast Properties" for the optimized, shape-based representation.
"Slow Properties" for the dictionary-based representation.

For more information about the subject, also refer to this blog post by Camillo Bruni on V8's website: https://v8.dev/blog/fast-properties

What causes V8 to switch to "Dictionary Mode"?

I asked myself the same question after encountering a scenario in which an object unexpectedly switched to Dictionary mode.

It turns out you can run Node.js with the flag --allow-natives-syntax.

This enables certain internal V8 functions, known as intrinsics, whose names begin with the % character.

One particularly useful function is %HasFastProperties(object), which allows us to inspect whether a JavaScript object currently uses V8's fast-property representation.

I asked my friendly neighborhood AI (Codex) to create a thorough test suite to investigate exactly when, and under which circumstances, V8 decides to switch an object into dictionary mode.

The repo for the audit suite can be found here:
https://github.com/yuval-a/v8-object-storage-audit/tree/main

Here's a summary of the findings.

Findings

Be advised, these were tested on November 21, 2026; V8 engineers can decide to make changes over time, use this as a general guide and not an absolute source of truth. I will put a link to the audit code that Codex created at the end.\

The following are Javascript operations that trigger a switch on an Object from the default "fast mode" to "slow dictionary mode"

Tested on Node version: 24.20.0, V8 version: 13.6.233.17

  • Use null as a Prototype for creating an object.

    Object.create(null);
    Object.create(null, descriptors);
    
  • Convert an existing data property into an accessor property.

    const object = {};
    Object.defineProperty(object, "property", {
      value: 1, writable: true,
      enumerable: true, configurable: true
    });
    
    // Convert from data property to accessor
    Object.defineProperty(object, "property", {
      get() { return 2; }
    });
    
  • Change the enumerable setting of an existing accessor property.

    const object = {};
    Object.defineProperty(object, "property", {
      get() { return 1; },
      enumerable: false, configurable: true
    });
    
    // Was false
    Object.defineProperty(object, "property", { enumerable: true });
    
  • Change the configurable setting of an existing accessor property.

    const object = {};
    Object.defineProperty(object, "property", {
      get() { return 1; },
      enumerable: false, configurable: true
    });
    
    // Was true
    Object.defineProperty(object, "property", { configurable: false });
    
  • Replace the getter of an existing accessor property.

    const object = {};
    Object.defineProperty(object, "property", {
      get() { return 1; },
      enumerable: false, configurable: true
    });
    
    // Replace existing getter
    Object.defineProperty(object, "property", {
      get() { return 2; }
    });
    
  • Delete the only property of an object.

    const object = { property: 1 };
    delete object.property;
    
  • Delete the first property of an object.

    const object = { property: 1, middle: 2, last: 3 };
    delete object.property;
    
  • Delete a property in the middle of an object.

    const object = { first: 1, property: 2, last: 3 };
    delete object.property;
    
  • Delete the last property of an object.

    const object = { first: 1, middle: 2, property: 3 };
    delete object.property;
    
  • Using a "fast object" as the prototype passed toObject.create switches
    the prototype object (but not the newly created object).

    const object = {
        property: 1
    };
    
    %HasFastProperties(object); // Was true
    
    const child = Object.create(object);
    
    %HasFastProperties(object); // Is now false
    %HasFastProperties(child);  // Is true 
    
  • Installing a fast object as another object's prototype switches the prototype object, not the child.

    const object = {
        property: 1
    };
    const child = {};
    
    %HasFastProperties(object); // Was true
    
    Object.setPrototypeOf(child, object);
    
    %HasFastProperties(object); // Is now false
    %HasFastProperties(child);  // Is true
    
  • Assigning a very distant numeric index on an ordinary object switches its indexed elements, not its named properties.

    const object = {};
    
    %HasFastElements(object); // Was true
    
    object[1_000_000] = "property";
    
    %HasDictionaryElements(object); // Is now true
    %HasFastProperties(object);     // Is still true
    
  • Assigning a very distant Array index switches the Array's indexed elements to dictionary elements while its named properties stays fast.

    const array = ["property"];
    
    %HasFastElements(array); // Was true
    
    array[1_000_000] = "property";
    
    %HasDictionaryElements(array); // Is now true
    %HasFastProperties(array);     // Is still true
    
  • Converting an Array index into an accessor switches the Array's indexed elements to dictionary elements.

    const array = ["first", "property", "last"];
    
    %HasFastElements(array); // Was true
    
    Object.defineProperty(array, "1", {
        get() {
            return "property";
        },
        configurable: true
    });
    
    %HasDictionaryElements(array); // Is now true
    
  • Making an Array index non-configurable switched the Array's indexed elements to dictionary elements.

    const array = ["first", "property", "last"];
    
    %HasFastElements(array); // Was true
    
    Object.defineProperty(array, "1", {
        configurable: false
    });
    
    %HasDictionaryElements(array); // Is now true
    
  • Repeated string-key assignment switches at count 20.

    const object = {};
    const dictionaryCount = 20;
    
    for (let index = 0; index < dictionaryCount - 1; index++) {
        object[`existingProperty${index}`] = index;
    }
    
    %HasFastProperties(object); // Was true
    
    object.property = dictionaryCount - 1;
    
    %HasFastProperties(object); // Is now false
    
  • Repeated configurable data-property definitions switches at count 1021.

    const object = {};
    const dictionaryCount = 1021;
    
    for (let index = 0; index < dictionaryCount - 1; index++) {
        Object.defineProperty(object, `existingProperty${index}`, {
                value: index,
                writable: true,
                enumerable: true,
                configurable: true
            });
    }
    
    %HasFastProperties(object); // Was true
    
    Object.defineProperty(object, "property", {
        value: dictionaryCount - 1,
        writable: true,
        enumerable: true,
        configurable: true
    });
    
    %HasFastProperties(object); // Is now false
    
  • Repeated configurable accessor definitions switches at count 1021.

    const object = {};
    const dictionaryCount = 1021;
    
    for (let index = 0; index < dictionaryCount - 1; index++) {
        Object.defineProperty(object, `existingProperty${index}`, {
                get() {
                    return index;
                },
                enumerable: true,
                configurable: true
            });
    }
    
    %HasFastProperties(object); // Was true
    
    Object.defineProperty(object, "property", {
        get() {
            return dictionaryCount - 1;
        },
        enumerable: true,
        configurable: true
    });
    
    %HasFastProperties(object); // Is now false
    
  • Repeated Symbol-key assignment switches at count 20.

    const object = {};
    const dictionaryCount = 20;
    
    for (let index = 0; index < dictionaryCount - 1; index++) {
        object[Symbol(index)] = index;
    }
    
    %HasFastProperties(object); // Was true
    
    const property = Symbol("property");
    object[property] = dictionaryCount - 1;
    
    %HasFastProperties(object); // Is now false
    
  • Repeated named-property assignment on an Array switches its named properties, not its indexed elements, at count 16.

    const object = [];
    const dictionaryCount = 16;
    
    for (let index = 0; index < dictionaryCount - 1; index++) {
        object[`existingProperty${index}`] = index;
    }
    
    %HasFastProperties(object); // Was true
    
    object.property = dictionaryCount - 1;
    
    %HasFastProperties(object); // Is now false
    

About the author

  • Raised in a family of programmers. Started writing Assembly code at the age of 13. Turned to web development at the age of 26. I like creativity and innovation. The combinations between high-level and low-level, between specifics and abstractions, between art and technology. Creator of the DeriveJS ODM for MongoDB: a back-end framework that enables you to use normal JS classes and objects as "data entities" that automatically sync and persist to MongoDB collections and documents, plus an engine that auto bulks your data operations for performance. Creator of SproutJS: https://jssprout.com, a client-side framework that adds reactivity and state management to native HTML elements, using Web Components / Custom Elements.

No comments yet. Be the first to comment.