The fastest is in-object storage, which only needs a lookup for the key in the HiddenClass to find the index into the in-object storage space. The properties themselves can be stored in three places. If there is a matching transition, it is reused, otherwise a new HiddenClass is created and added to the transition tree. These transitions are saved in a HiddenClass chain, which is consulted when new objects are created with the same named properties, or the properties are added in the same order. Adding a named property to an object results in the creation of a new HiddenClass, which contains the storage details for all the previous properties and the new one, then the map of the object is updated, as shown below (figures from the v8 dev blog). JS engines only create a single HiddenClass for a given shape, which is shared by every object that has the same structure. However, since it is not possible to know the property configuration of objects in a prototype-based language like JavaScript in advance, they are created on demand. HiddenClasses are similar in concept to classes in object-oriented languages. The storage of object shapes in a HiddenClass is another attempt at saving storage space. This information, among other things, is provided by the map (or HiddenClass) of the object. String keyed values are also stored in an array but to get the index corresponding to the key, another level of indirection is needed. This allows the engines to potentially use continuous arrays for properties with integer keys, where the index maps directly to the underlying storage, speeding up access. A common technique is to use separate backing stores for the integer keys (often called elements) and string/Symbol keys (usually referred to as slots or named properties). JS engines implement several optimizations on the property storage of objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |