Hacker News new | ask | show | jobs
by antirez 8 days ago
It uses two techniques: B+ tree instead of sorted sets, but also the hash table side, the dictionary, is specialized for sorted sets and stores several items per allocation. The B+ tree leaves hold all the members and scores (also in clusters of many elements, 96 max or 4k: that's a big part of the win), rank lookup can skip many children because of meta data, which is part of the ability to go as fast or faster than Redis even if the memory is so much smaller. The hash table points to leaves in the B+ tree, does not have elements at all, and is heavily optimized to do just the minimum, a single byte tag is used as a speed optimization to optimized lookups in an optimistic way. Basically it is the sum of many different techniques conceived during the years and never adopted for fear of complexity (today no longer a problem), and newely discovered techniques.

P.S. I tried several variants with different representations, so this specific implementation is the Pareto frontier in speed/size of many, many attempts.

2 comments

EDIT: "b+ trees instead of skiplists" of course. Sorry, can't edit it anymore.
One (of many) questions,

  today no longer a problem
To be sure, you think these problems are tackleable now due to AI (my impression of your comment)? Or to advances in {yourself}/{else} in the ecosystem? How do you deal with managing the complexity now? Is it 'easier' because we as humans no longer need to do the decently complex step of writing most of it? Or iterations/... enabled by AI are able to reduce the long tails around experimenting/benchmarking with these kinds of complex structures?
Now this can be handled because of development speed but especially because the level of testing coverage you can get today with AI, and even static scrutiny, is immense. So before the frontier models of the latest months there was no way to do something like that without increasing the fragility of the implementation. Now it was possible to try tons of approaches, pick the best, iterate on testing a lot.