In ECMAScript, every object looks like an arbitrary dictionary mapping string or symbol keys to values. In practice, however, JavaScript objects are used in two very different ways:
obj.x, obj.y): Usually a small, fixed set of string/symbol keys shared across many instances of a class or literal.arr[0], obj[42]): Array-like integer indices (0 <= index < 2^32 - 1) that are iterated sequentially, resized dynamically, or stored densely.To optimize both access patterns simultaneously, every JSObject in V8 splits its storage into two independent tracks:
properties_or_hash_) + In-Object Fields: Controlled by the Map's DescriptorArray (in fast mode) or a SwissNameDictionary / NameDictionary (in dictionary mode).elements_): Controlled by the Map's ElementsKind, storing indexed values in contiguous arrays (FixedArray, FixedDoubleArray) or sparse dictionaries (NumberDictionary).+-------------------------------------------------------------------+ | JSObject | +-------------------------------------------------------------------+ | map_ (Tagged<Map>: hidden class + ElementsKind) | | properties_or_hash_ (PropertyArray, SwissNameDictionary, or Smi) | | elements_ (FixedArray, FixedDoubleArray, or Dictionary) | +-------------------------------------------------------------------+ | In-Object Field 0 (1 tagged word: Smi, HeapObject, HeapNumber) | | In-Object Field 1 (1 tagged word) | | ... | +-------------------------------------------------------------------+
PropertyArray, and RepresentationPropertyArray) FieldsWhen a JSObject is created, its Map reserves a fixed number of in-object property slots directly inside the JSObject allocation (map->GetInObjectProperties()).
JSObject pointer itself (*(object_ptr + offset)).PropertyArray pointed to by properties_or_hash_ (requiring one extra load).JSObject (map->UnusedPropertyFields()) allows new properties to be added in-place by simply transitioning the Map and writing to the next unused slot.Representation::Double() (Field Unboxing vs Boxing)Every named property field in a JSObject or PropertyArray is exactly one tagged word (kTaggedSize bytes) wide (PropertyDetails::field_width_in_words() == 1):
kTaggedSize is 4 bytes, whereas an IEEE-754 double (kDoubleSize) is 8 bytes.double cannot fit inline inside a 4-byte compressed tagged field slot, Representation::Double() fields are NOT stored as raw 8-byte unboxed doubles directly inside the JSObject field slot.Representation::Double() stores a tagged pointer to a dedicated, mutable HeapNumber box (allocated via JSObject::AllocateStorageForMap or JSDataObjectBuilder).Representation::Double() if it still points to a HeapNumber?Representation::Tagged() field, assigning a new float (obj.x = 3.14; obj.x = 2.71;) must allocate a brand-new immutable HeapNumber on every write because other pointers might alias the old HeapNumber. For a Representation::Double() field, the JSObject exclusively owns the HeapNumber box at that slot! Stores simply overwrite the 64-bit double payload inside the existing HeapNumber in-place without allocating. (Conversely, reading a Representation::Double() field into a generic tagged value must allocate a fresh HeapNumber copy or unbox the float into an FP register so external code cannot observe future in-place mutations.)Map that the field points to a HeapNumber and can load/store the 64-bit double directly in floating-point registers.Each kField descriptor tracks a Representation (src/objects/property-details.h) that starts narrow and widens monotonically as values are stored:
Smi -> Double: Storing 3.5 into a Smi field widens the field's representation to Double. Because a Smi was stored inline in the slot whereas a Double field requires a dedicated HeapNumber box, transitioning an existing instance from Smi to Double requires instance migration (JSObject::MigrateInstance allocates the HeapNumber box and boxes the old Smi value into it).Double -> Tagged: Storing a non-number (e.g., "hello" or undefined when V8_ENABLE_UNDEFINED_DOUBLE is not active) into a Double field widens it to Tagged.HeapObject -> Tagged: A Representation::HeapObject() field exclusively holds tagged HeapObject pointers (MachineType::TaggedPointer(), including immutable HeapNumber boxes for Smi-range numbers), allowing JIT compilers to omit Smi checks on loads. Storing a raw Smi generalizes the field to Tagged, and any compiler store or backing-store copy targeting a HeapObject slot must preserve its TaggedPointer representation.SwissNameDictionaryWhen an object has too many properties (> kMaxNumberOfDescriptors = 1020), uses delete obj.prop (which would otherwise leave holes or break shared DescriptorArray prefixes), or exhibits megamorphic shape churn, V8 normalizes its named properties into dictionary mode (map->is_dictionary_map()).
In modern V8 (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL), dictionary-mode JSObjects use SwissNameDictionary (src/objects/swiss-name-dictionary.h) instead of the legacy NameDictionary (which is still used on JSGlobalObject via GlobalDictionary or when Swiss dictionaries are disabled).
SwissNameDictionary Architecture (SwissTable / Abseil flat_hash_map)SwissNameDictionary adapts Abseil's SIMD-accelerated open-addressed hash table (SwissTable) to the V8 heap while preserving exact property insertion order:
+-------------------------------------------------------------------------+ | Map (swiss_name_dictionary_map) | | prefix (uint32_t: identity hash) | capacity (int32_t: power of 2 or 0) | | meta_table_pointer (Tagged<ByteArray>: count, deleted, enum table) | +-------------------------------------------------------------------------+ | data_table: 2 * capacity Tagged slots [ key_0, val_0, key_1, val_1... ] | +-------------------------------------------------------------------------+ | ctrl_table: (capacity + kGroupWidth) uint8_t bytes (H2 hash / Empty) | +-------------------------------------------------------------------------+ | property_details_table: capacity uint8_t bytes (1-byte PropertyDetails) | +-------------------------------------------------------------------------+
ctrl_table):kGroupWidth = 16 or 8 bytes) and H2 (a 7-bit fingerprint stored in the ctrl_table byte for that bucket; high bit 1 indicates Ctrl::kEmpty = 0b10000000 or Ctrl::kDeleted = 0b11111110).data_table keys occur only when the 7-bit H2 fingerprint matches!PropertyDetails (property_details_table):FieldIndex or 10-bit DescriptorPointer, each bucket's PropertyDetails (PropertyKind, PropertyAttributes, PropertyCellType/Constness) fits into a single byte (PropertyDetails::ToByte() / FromByte()). Properties keyed by any private symbol (Name::IsAnyPrivate(), including internal private symbols and private names) must always have the DONT_ENUM attribute set in both fast descriptor arrays and dictionary properties (SwissNameDictionary and NameDictionary).meta_table):for..in or Object.keys().SwissNameDictionary eliminates sorting completely: its meta_table (ByteArray) appends the bucket index of each newly inserted entry into a compact array of uint8_t (when capacity <= 256), uint16_t, or uint32_t integers. Iterating properties in insertion order simply walks the meta_table entries sequentially!ElementsKind Transitions (src/objects/elements-kind.h)The elements_ pointer of a JSObject or JSArray stores integer-indexed properties (0, 1, 2, ...). A Map's ElementsKind bitfield tracks both the element representation and whether the backing store is packed (dense from 0 to length - 1) or holey (may contain the_hole_value / kHoleNanInt64 gaps that require prototype chain lookups if read).
ElementsKind Transition LatticeAs elements are stored or deleted, a JSArray transitions one way from more specific to more general ElementsKinds:
PACKED_* vs HOLEY_*: If an array has PACKED_* elements, any access within 0 <= i < array.length is guaranteed not to hit an element hole, allowing Maglev and TurboFan to elide both the hole check and the fallback prototype-chain lookup (Array.prototype check). Once an array transitions to HOLEY_* (e.g., via new Array(10), arr[5] = 1 past length, or delete arr[0]), it never transitions back to PACKED_*.*SMI_ELEMENTS & *ELEMENTS (FixedArray) vs *DOUBLE_ELEMENTS (FixedDoubleArray):FixedArray stores tagged pointers (kTaggedSize bytes per element; the_hole_value marks holes).FixedDoubleArray stores raw 64-bit IEEE-754 doubles (8 bytes per element even when pointer compression is enabled; kHoleNanInt64 marks holes -- see Holes and Sentinels). Transitioning from SMI to DOUBLE or from DOUBLE to ELEMENTS reallocates and converts the entire backing store.[!WARNING]
ElementsKindEnum Order != Transition Order! Insrc/objects/elements-kind.h, the numeric enum values are ordered as:
0:PACKED_SMI_ELEMENTS1:HOLEY_SMI_ELEMENTS2:PACKED_ELEMENTS3:HOLEY_ELEMENTS4:PACKED_DOUBLE_ELEMENTS5:HOLEY_DOUBLE_ELEMENTSNotice that
PACKED_ELEMENTS(2) andHOLEY_ELEMENTS(3) have lower numeric enum values thanPACKED_DOUBLE_ELEMENTS(4) andHOLEY_DOUBLE_ELEMENTS(5)! V8 groups the fourFixedArray-backed kinds (0..3) together so generated code can check “is this a fast Smi-or-ObjectFixedArraybacking store?” with a single unsigned comparison (kind <= HOLEY_ELEMENTS).Never compare two
ElementsKindenum values with<or>to test which is more general! Always useIsMoreGeneralElementsKindTransition(from, to)orGetNextTransitionElementsKind(kind)(src/objects/elements-kind.cc), which consultskFastElementsKindSequence:PACKED_SMI -> HOLEY_SMI -> PACKED_DOUBLE -> HOLEY_DOUBLE -> PACKED -> HOLEY.
MapUpdater and Map Generalization (src/objects/map-updater.h)What happens when an existing property on an instance receives a value that violates the current Map's PropertyConstness, Representation, or FieldType (for example, storing 1.5 into a Representation::Smi() field, or storing a Bar instance into a FieldType::Class(Foo) field)?
Simply creating a new branched Map would cause polymorphic/megamorphic map explosion across instances created by the same constructor. Instead, MapUpdater (src/objects/map-updater.cc) generalizes the transition tree so all existing and future instances converge on a unified target Map:
TryReconfigureToDataFieldInplace)When the transition does not require reallocating field storage (for example, changing PropertyConstness::kConst to kMutable, widening FieldType::Class(Foo) to FieldType::Any(), or widening Representation::Smi() or HeapObject() directly to Representation::Tagged() without Double unboxing):
MapUpdater updates the PropertyDetails and FieldType in-place inside the existing DescriptorArray!kConst or FieldType assumption via DependentCode::DeoptimizeDependencyGroups (kFieldConstGroup, kFieldTypeGroup, kFieldRepresentationGroup).MapUpdater Pipeline)When a transition requires changing physical field layout (such as widening Representation::Smi() to Representation::Double(), which requires allocating a mutable HeapNumber box) or changing property attributes:
FindRootMap(): Walks backward along map->GetBackPointer() up the transition tree to find the root Map (before any diverging field representations).FindTargetMap(): Replays the updated sequence of property descriptors forward from the root Map through existing transitions (TransitionsAccessor), checking if a compatible generalized branch already exists.BuildDescriptorArray(): If no complete target Map exists, merges the descriptor representations, constness, and FieldTypes of the old Map and the new requirement into a generalized DescriptorArray.FindSplitMap(): Finds the ancestor Map where the old transition branch and the new generalized branch diverge, and deprecates (map->DeprecateTransitionTree()) the superseded old Map subtree (setting their raw_transitions() to kMigrationTarget and deoptimizing code in kTransitionGroup).ConstructNewMap() / ConstructNewMapWithIntegrityLevelTransition(): Allocates the remaining Map nodes along the generalized branch from the split point.JSObject::MigrateInstance(): Whenever an instance with a deprecated Map is encountered by an IC, runtime call, or compiler check (TryMigrateInstance), V8 migrates the instance in-place to the new generalized Map (allocating HeapNumber boxes for any newly Double-represented fields).src/objects/js-objects.h & src/objects/js-objects.cc: JSObject layout, MigrateInstance, and AllocateStorageForMap.src/objects/swiss-name-dictionary.h & src/objects/swiss-name-dictionary-inl.h: SwissNameDictionary SIMD/SWAR hash table.src/objects/elements-kind.h & src/objects/elements-kind.cc: ElementsKind definitions and kFastElementsKindSequence.src/objects/elements.cc: ElementsAccessor implementations for each ElementsKind.src/objects/map-updater.h & src/objects/map-updater.cc: MapUpdater state machine and in-place field generalization.