Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So JS objects can be used for two conflicting purposes. They can be used as objects but they can be used as hash tables too. However what is fast and makes sense for objects is not so for hash tables, so V8 tries to guess what a given object is.</p> <p>Some signs the user can give that he wants a dictionary are deleting a property or <a href="https://github.com/v8/v8/blob/9bdbbc29b41c496f7fd68f75ad6c1f2d78df0f87/src/objects.cc#L8015" rel="nofollow">giving a property a name that cannot be accessed using dot notation</a>.</p> <p>Some other heuristics are also used, I have made a gist <a href="https://gist.github.com/petkaantonov/6327915" rel="nofollow">https://gist.github.com/petkaantonov/6327915</a>.</p> <p>There is however <a href="https://github.com/v8/v8/blob/9bdbbc29b41c496f7fd68f75ad6c1f2d78df0f87/src/objects.cc#L9593" rel="nofollow">a really cool hack</a> that redempts an object from hash table hell:</p> <pre><code>function ensureFastProperties(obj) { function f() {} f.prototype = obj; return obj; } </code></pre> <p>See it in action: <a href="http://jsperf.com/property-dash-parformance/2" rel="nofollow">http://jsperf.com/property-dash-parformance/2</a>.</p> <p>The redempted object is not as fast as the original because the properties are stored in the external properties array rather than in-object. But that's still far better than hash table. Note that this is still pretty broken benchmark, do not think for a second that hash tables are only 2x slower than inobject properties.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload