![]() The idea is that, for a given constructor, V8 initially allocates a generous amount of memory, enough for storing its properties as in-object properties (up to a maximum that we will see later). To determine the appropriate size for objects, V8 uses something called "in-object slack tracking". We don't want to reallocate objects every time a new property is added, neither do we want to allocate a big chunk of memory for tiny objects. How many in-object properties does V8 reserve for an object? How much memory is thus allocated? Now let's dig even deeper and find out how V8 actually represents objects in memory. The series of transitions that lead to a hidden class is called a 'Transition tree' and is stored by V8. ![]() Note: it's much better to initialise dynamic properties in the same order so that hidden classes can be reused. By doing this, different hidden classes are created and you are therefore precluding some of the optimisations V8 could otherwise provide. `obj1` and `obj2` do not have the same hidden class because their properties are not declared in the same order. We will eventually get the following hidden classes and their transitions. C0 is updated with a "class transition" which states that if a property "b" is added to an empty object, the hidden class should switch from C0 to C4. (6) V8 creates a hidden class C4 based on C0. C4 describes the location in the memory where the property 'b' can be found. (5) V8 can use the hidden class C0 to define 'obj2' as en empty object. Now we have 4 hidden classes, linked as such: C1 is updated with a "class transition" which states that if a property "b" is added to an object whose hidden class is C1, then the hidden class should be switched to C2. (3) V8 creates a hidden class C2 based on C1 the same way as before. C0 is updated with a "class transition" which states that if a property "a" is added to an empty object, the hidden class should switch from C0 to C1. C1 describes the location in memory where the property 'a' can be found. (2) V8 creates a hidden class C1 based on C0. ![]() ![]() (1) V8 creates a hidden class C0 for 'obj1' defining an empty object. We will later see what information this hidden class holds. ![]()
0 Comments
Leave a Reply. |