HN2new | past | comments | ask | show | jobs | submitlogin

Very interesting ! You mentioned the memory usage at the end, BTreeMaps are actually better than HashMaps most of the time, at least for Rust

Here's a good break down: https://ntietz.com/blog/rust-hashmap-overhead/



Btrees don't waste much memory, while hash tables have to have excess capacity if you want them to go fast.


That's true for on-disk b-trees which typically have large node sizes (typically 4KB), but in-memory btrees tend to aim for CPU cache lines (typically a small multiple of 32B), and thus do actually waste a fair amount of memory with their comparatively low branching factor, and thus relatively large number of branches compared to their number of leaves.


The waste of abseil's b-tree, for example, is small per value: https://abseil.io/about/design/btree

The efficiency compared to hash tables very much does carry over to the small b-trees used for in-memory data.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: