A delete keeps shared shapes within a budget and otherwise makes the object a dictionary
Date: 2026-11-29
Area: engine, memory
Related: ADR 0202, #2297
Context
ES2026 §10.1.10.1 OrdinaryDelete removes a configurable own property, and §10.1.11.1 OrdinaryOwnPropertyKeys lists
the remaining string and symbol keys in the order they were created. An object's shape holds those keys in order,
and objects built the same way share shapes along their prototype's transition tree, which is what the inline caches
key on. A transition shape lives as long as its prototype, so for an object whose prototype is Object.prototype
it lives as long as the engine.
DeleteProperty rebuilt the object's shape from its prototype's root shape, adding every key but the deleted one
again. Every key after the deleted one took a new transition shape unless an earlier object had built that exact key
sequence. A wide object took a whole new dictionary on each delete, its keys added one by one. Deleting the keys of
an object one by one therefore made shapes in proportion to the square of its size. An object used as a cache, with a
fresh key added and the oldest deleted, made a new chain of shapes on every eviction that nothing would ever reuse.
On Linux x86-64 (--prod), five passes that add and delete 1,400 keys reached 279 MB. A cache of 48 keys took
8.6 s and 2.6 GB for 200,000 evictions. A 70-key object that deleted and re-added one key 200,000 times reached
890 MB. Shapes count against --max-memory (ADR 0202), so a script under a limit was refused instead.
The alternatives:
- Always make the object a dictionary on a delete other than its last key's, as V8 does. Dictionary shapes belong to one object, and the inline caches skip them. 20,000 similar objects that each lost one key were read 13 times slower than with shared shapes.
- Delete from a dictionary in place, under a new version. A key's slot would move while the shape keeps its
address. That is safe only while every cache that can hold a dictionary shape also compares its version or skips
dictionaries, an invariant on every cache, present and future. An in-place add keeps every slot where it was, and
ChangeFlagsalready gives a dictionary a new identity for the same reason. - Rebuild, but limit how many keys may follow the deleted one. With a limit of 8, similar 12-key objects that each lost their second key all became dictionaries, and their reads were 13 times slower. A cache of 8 keys still made 7 shapes on every eviction.
Decision
- A delete moves an object to the shape without the key. The keys before the deleted one are an ancestor's, found up the parent chain. The keys after it follow that ancestor's existing transitions. Deleting the last key added goes back to the parent shape, and similar objects that lose the same key share the same shape.
- New shapes for the keys after it are made only in an object's first four rebuilds (
DELETE_REBUILDS_MAX).TShape.DeleteDepthcounts them: a shape a delete makes has its object's count plus one, and a shape's children have its count. A delete that can follow existing transitions all the way needs no budget. - Otherwise the object becomes a dictionary. So does every non-extensible object, and every object whose shape was forked (no parent chain), so a non-extensible object is never put on a shape that extensible objects share.
- A dictionary belongs to its object alone. The add-transition cache of
XSetPropSlowno longer records a transition into a dictionary, as the other two fill sites already did not: a second object of the same 64-key shape took the first one's dictionary through it, and then saw the first object's keys. - A delete from a dictionary gives it a new identity that takes over the old one's arrays. The keys after the deleted one move down in place, and the hash table is filled again in place. The record left behind holds nothing and is retired by the next major collection, as ADR 0202 retires a dictionary no object has.
Consequences
- Each delete adds at most a fixed amount to what the engine keeps. Five passes of 1,400 keys take 22 ms and 22 MB (from 137 ms and 279 MB), the 48-key cache 120 ms and 60 MB (from 8.6 s and 2.6 GB), and the 70-key churn 66 ms and 53 MB (from 303 ms and 890 MB). Similar objects that lose one or three keys read as fast as before.
- A delete moves the values of the keys after the deleted one down a slot, as before, and clears the slot it frees, so a deleted value no longer stays reachable through the object's overflow slots.
- A delete on a non-extensible object no longer gives it a shared tree shape. Before, an add-transition cache filled
by an extensible object of the same shape could add a property to it. Freezing and sealing still rebuild the shape
in
ChangeFlagsand leave the same opening, which #2321 tracks. - Objects that reach their 65th key through the same store site no longer share a dictionary, so a key added to one no longer shows in the other.
- An object whose deletes used up its budget, or whose shape was forked, stays a dictionary. The inline caches skip it, and its property accesses take the uncached lookup.