I've always avoided maps because I read long ago that they're the wrong tool for pretty much any job, clearly that's wrong. Where DO they make sense? What are some cases they perform better in? (Alternatively, what made it the right choice for Jest?)
-
-
-
Whenever you need the concept of a lookup table without the need to walk up the prototype chain for missing properties, use a map, not an object.
- 2 more replies
New conversation -
-
-
I wonder if
@nodejs could improve performance by doing this
-
Actually I'm pretty sure the module cache would work way faster with a Map instead. So much userland code relying on `delete require._cache[key]` though.
- 2 more replies
New conversation -
-
-
I spent some time optimizing Prettier for large files some time ago, and benchmarks were showing Map is slower than Object on reads (I assumed because of the method calls versus index operator). IIRC, on Node 8. https://github.com/prettier/prettier/issues/4776#issuecomment-401569405 … (the change didn't go in for another reason)
-
I think Node 8 was using pretty old V8 with unoptimised Map.
- 3 more replies
New conversation -
-
-
How does the performance of `Map` compare to `Object.create(null)`? I'm curious since I'm assuming the major performance change here was not having to walk up the prototype chain when performing lookups
-
Jest were doing exactly that, creating an object with null for prototype and there were still performance gains. My guess is because Objects can do a lot, so they come with a lot of overhead, Maps are pretty lightweight, so V8 can optimise them well.
- 1 more reply
New conversation -
-
-
"The performance of Map is much better than Object to implement dictionaries when they contain a large amount of entries". Do you know, currently, how large is "large"? Also, is it impacted by how often the dictionary needs to be mutated?
-
I don't think so. All the operations seem to be faster in Map than in Object. You can check here: https://jsperf.com/map-vs-object-operations …
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Jest reduced their test runner time by 20% by switching from plain JavaScript objects to Maps where it made sense.