Hacker News new | ask | show | jobs
by antirez 12 days ago
For par condicio: I worked at a similar optimization for Redis using different techniques (when I submitted the PR my colleagues informed me that ValKey and another Redis team was working at it, I was not aware: the amoung the three implementation we picked mine after extensive benchmarks) reaching memory savings that sometimes can be tens of percentage of less RAM compared to this ValKey optimization. So if you are exited for less memory for sorted Sets you should try both the implementations. We also got a lot more speed in many use cases compared to the skiplist.
2 comments

Is your implementation also a B+ tree? If so how does it use tens of percentage less memory? less metadata?
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.

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.
Why do you think another option was chosen instead?