4 ms·
Also wondering this. I found a comment on StackOverflow from 2015 [0] that might offer some insight: > "It's probably worth mentioning that V8 goes to great le
by chatmasta 9y ago
Also wondering this. I found a comment on StackOverflow from 2015 [0] that might offer some insight:
> "It's probably worth mentioning that V8 goes to great lengths to avoid using a hash table for object properties whenever possible, preferring to compile known property references into direct index references rather than run-time hash lookups for performance reasons (though this is only possible sometimes - depends upon the code)."
Since this blog posts mentions they store the hash code as a property of the object, that might imply they are using "direct index references" instead of computing the hash at runtime.
It does seem like a couple layers of indirection, though. This is way outside my expertise, so I would love to hear some more comments on this.
[0] https://stackoverflow.com/a/30695791/7252597 https://stackoverflow.com/a/30695791/7252597
- deleted 9y ago[deleted]
- gnode 9y agoThe hash cannot be computed, because it's not really a hash at all. In JavaScript's Map and Set, Objects are considered equivalent if they are the same object instance, not if their contents are the same. So really the "hash" is a unique tag. I believe the object's memory location can not be used, as the object may be relocated, and/or a different object stored at the same location at a later time.