3 ms·
No, dynamic languages use Maps and Dictionaries and Objects and Containers and... Sure, they're all hash tables under the hood, but if you go up to an average
by falcolas 10y ago
No, dynamic languages use Maps and Dictionaries and Objects and Containers and...
Sure, they're all hash tables under the hood, but if you go up to an average JavaScript programmer and ask them the difference between a Hash Table and an Object, I'm sure you'd get a surprising (to you) answer.
- emodendroket 10y agoI mean, not even under the hood. Those are just different names for the same thing.
- masklinn 10y agoDue to the way JS objects are used, modern runtime will generally try to use structures for them (e.g. "hidden classes" in V8/Chrome) rather than "general-purpose" hashmaps. Likewise JS arrays incidentally. They will often need to deoptimise back to general-purpose hashmaps, but they'll try pretty hard not to.
- emodendroket 10y agoOh. That's neat.
- masklinn 10y agoYep. V8's JIT will also try to specialise functions based on that so if you always pass the same type (where type = hidden class), a limited number of types or "anything goes". Or at least it did a few years back.
- DiThi 10y agoIf an object is being used as a hash map, you can avoid hidden class optimizations by deleting whatever from it: var map = {}; delete map.x;