After exploring the answer to whether v8 rehashes when an object grows, I am intrigued by how v8 manages to store "fast" objects.
According to the response:
Fast mode for property access is significantly faster, but it requires knowledge of the object's structure.
V8 initially creates a template of the object's makeup called a "Hidden Class". As the object evolves, it transitions through hidden classes until V8 resorts to storing it as a slow property.
I then inquired about whether v8 rehashes as an object expands, and this was the explanation provided:
There is no hashing involved at all - it operates based on memory access offsets, similar to a C struct.
(for fast mode objects)
The information also includes:
Objects in this scenario are not stored as hash maps; instead, they rely on a hidden class.
To sum up, despite modifications to object properties, the underlying structure preserves a hidden class:
var x = { a: 1, b: 2, c: 3 }
x.d = 4
x.e = 5
x.f = 6
Based on the insights shared, v8 does not employ a hashtable for value storage; rather, it utilizes a hidden class. The question arises: how does v8 effectively store values as a hidden class struct? What functions does the hidden class fulfill, what is its organization, and how does it function? When you later reference var d = 'd'; x[d]
in your code (to make it dynamic), how does it pinpoint the location of the value for d
without relying on hashing the property as a string to obtain the index (in theory)? How does it locate the memory address of the struct with respect to the key?