5 ms·
JavaScript also lacks a proper hash table. I wonder how much faster a native implementation could possibly be over say `Map()` (which keeps insertion order by m
by frankenst1 6y ago
JavaScript also lacks a proper hash table. I wonder how much faster a native implementation could possibly be over say `Map()` (which keeps insertion order by maintaining linked lists and does not have constant op).
- perlgeek 6y agoWhat's wrong with using objects as hashes?
- tyingq 6y agoThere's a table at the bottom of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... that shows some reasons why.
- frankenst1 6y agoThey can be faster than `Map` but: 1) Slower than hash tables 2) `{}` is not empty but has default keys 3) `{}` has multiple read-only keys 2 and 3 are caused by the prototype chain (properties not present on the initial object will be attempted to be resolved via the prototype hierarchy) which can be avoided via `Object.create(null)`