by Const-me · 3y ago · 0 comments
I have copy-pasted B+ tree from TLX https://github.com/tlx/tlx (Boost license), and then I did some local changes to improve the performance for my specific keys and value types. I have used AVX2 intrinsics to improve search within nodes, and I also implemented a few more simple tricks. After these changes, the performance became satisfactory for my application.
Also a lot of assumptions from the past start to erode with the memory architecture and cache performance we have today. Things where one would reach for binary search or hash table before end up getting outperformed by linear scan, as long as the set of data fits roughly in a cache line, etc.
It's possible that in this day and age we'd all just be better off writing actually performance critical stuff in an APL offshoot, with the language forcing one to steer away from branching and dispatch whenever possible and deal with data in declared, bulk, array/vector-type operations.
https://dirtyhandscoding.github.io/posts/performance-compari...
The benchmark linked looks like the best case for linear search - searching a packed array of ints. Even then from the results after just 256 elements binary search starts to win out (comparing the optimised implementations of both). By 1024 elements the difference between O(log N) and O(N) complexity is clearly starting to dominate the results.
For more complex comparison functions, and pointer indirections (e.g. searching arrays of heap allocated objects), I’d assume the lower time complexity of binary search would dominate results even more.