3 ms·
A 10× Faster Hash Table for Node.js
- crooked-v 8y agoNo comparison with Set?
- jorangreef 8y agoThanks, I added Set into the rough vanilla comparison. It's slightly better than a vanilla object, but it's still almost an order of magnitude slower, and is most likely still going to have issues with GC overhead when storing millions of pointers. GC issues blocking the event loop are not fun when you have a hash table with billions of elements. Also, while a Set can technically receive an Array (or iterable) upfront in the constructor, this requires you to have your Array available upfront, which is not always the case, and an Array is also not meant for millions of objects in the first place. For example, AFAIK (and I may be wrong since last I checked) but V8's Array will switch mode and degrade into an object at around 10,000 elements. So with Set (or Map) there's still no production-quality way to allocate and reserve capacity upfront by the number of elements or size in bytes. Please note, the `vanilla.js` comparison in the Motivation section is not meant as a benchmark, but just to sketch the principles outlined there. You don't actually even see the 10× differential with `vanilla.js` because it only inserts 4,000,000 elements - I would have set it higher but Set and Object start taking forever or cause OOM crashes beyond that. More accurate, in-depth performance numbers are here: https://github.com/ronomon/hash-table#performance https://github.com/ronomon/hash-table#performance