Valkey 9.2's B+ Tree Sorted Sets, Measured

The Valkey 9.2 release notes say large sorted sets now use 36% to 43% less memory per member. I built 9.2.0 from source, built 8.0.13 from source on the same box, loaded the same million members into both, and measured. The saving I got was bigger than the claim, and my first reaction was that I had measured something wrong.
I had. Not the totals, which held up on a second run. What was off was what the numbers mean. The claim counts the index alone. My numbers count the whole key. Once you separate the two, the story gets more interesting than the headline, and less flattering in one specific place.
The setup is deliberately boring. One sorted set, a million members, each member a 20-byte name, scores running 1 to 1,000,000. I loaded it twice on each version: once in order, once shuffled. Both servers ran with the same settings, same allocator, same box, a small shared-CPU virtual machine, which matters for the throughput part below and not at all for the memory part. I read memory two ways for each load: the per-key figure and the server's own used-memory counter before and after. The two agreed within a couple of bytes per member, so I will quote the per-key figure and mention the other where it matters.
Here is the table that made me suspicious.
| Load | Valkey 9.2 | Valkey 8.0 | Saved |
|---|---|---|---|
| Sequential, 1M members | 58.41 bytes/member | 99.59 bytes/member | 41.18 bytes/member, 41.4% |
| Random order, 1M members | 62.30 bytes/member | 99.59 bytes/member | 37.29 bytes/member, 37.4% |
Two things jump out. First, the percentages land inside the claimed 36–43% band almost exactly: 41.4% sequential, 37.4% random order. Second, the absolute saving, 37 to 41 bytes per member, is roughly double what the claim implies. The release notes put the old index overhead at 50.3 bytes per member and the new one at 28.5 to 32.0, a saving of 18 to 22 bytes. My saving is twice that. Either the claim understates the win, or something else changed between 8.0 and 9.2 besides the sorted-set index.
Something else changed. To find what, I loaded the same million names as a plain set, same members, no scores, no index at all, on both versions. A set is just the member table plus the strings, so it tells me what the shared parts cost before the index enters the picture.
| Structure | Valkey 9.2 | Valkey 8.0 |
|---|---|---|
| Set, 1M members | 50.88 bytes/member | 38.79 bytes/member |
The new version's member table costs about 12 bytes per member MORE than the old one. Valkey 9.x replaced the old hash table with a new implementation, and on this load it is hungrier, not leaner. That flips the arithmetic: the total saving of 37 to 41 bytes is the fbtree's index saving MINUS the 12 bytes the new table gave back. The index itself must have saved roughly 49 to 53 bytes per member. That is more than the entire old index overhead the release notes quote.
I do not have a clean explanation for that gap, and I am not going to invent one. The release notes measured 5 million members on a 64-core machine with their own method; I measured 1 million on a small box with the per-key counter. Allocator rounding alone can move these figures by several bytes per member: a 56-byte node rounds up to a 64-byte size class, and a 60-byte node the same way, so two structures that differ by a few bytes on paper can differ by a whole size class in practice. What I can say with confidence is the thing a person upgrading actually cares about: the whole key got 37% to 41% smaller, and the index is not the only thing that moved. If you sized your fleet from the old per-member figure, the new total is what you will actually pay, and it is smaller than the claim's arithmetic suggests, not larger.
The release notes make a second claim about the new tree: it compacts sparse leaves when members are deleted, so a set that shrinks gives memory back. I tested that by deleting half the random-order set, 500,000 members out of a million, and measuring again.
On 9.2, deleting half the members freed 23.1 MB of the set's 62.3 MB, about 37%. On 8.0, the same deletion freed 45.6 MB of 99.6 MB, about 46%. In absolute terms the 9.2 set left behind is still far smaller, 39.2 MB for the remaining half-million against 54.0 MB on 8.0, but the new tree did not give back a bigger share than the old skiplist did. The reason is visible in the per-member cost of what remains: 78.43 bytes on 9.2 against 107.98 on 8.0. A fixed chunk of the cost is the member table, and that table does not shrink when members leave. Deleting half the members removes half the index, but the table stays the size it was built for. The compaction claim is about the tree, and the tree is only part of the key. Anyone planning to reclaim memory by deleting members should expect roughly a third of the set's memory back on 9.2, not half.
The third claim in the release notes is throughput: ZADD up 105%, ZREM up 76%. I could not reproduce any of that here, and the reason is probably my setup rather than their numbers. I loaded a million members with one client, sending them in batches of a thousand, and timed it twice per version. The times were 5.59 and 5.11 seconds on 9.2, 5.17 and 7.48 seconds on 8.0. The spread inside one version is bigger than the gap between versions. On a small shared-CPU box with one client, the load is limited by everything except the index: the client, the connection, the scheduler. Their numbers came from nine I/O threads and ten commands in flight at once on a 64-core machine. If your workload looks like mine, one client doing bulk loads, do not upgrade for speed. If it looks like theirs, my numbers say nothing about it either way.
So where does that leave the upgrade? The memory win is real, it is bigger than the headline in total terms, and it survives the most boring possible test: same data, same box, two versions, measured twice. The two caveats are the kind that only show up when you measure the whole key instead of the index: the new member table costs more than the old one, which means the tree is doing even more work than the release notes say, and deleting members gives back less than half the memory because the table does not shrink. Neither changes the decision. Both change the capacity maths you do after it.
I went in expecting to confirm a percentage. I came out with a different number than the one in the release notes, a member table that got more expensive while nobody was looking, and a deletion test that gives back a third instead of a half. The percentage checked out. The details did not, and the details are what you pay for.
P.S. Everything I write stays free — that part doesn't change. But if this one was worth something to you, you can buy me a coffee ☕ (one-time or monthly, both work). It covers the API credits and hosting behind these experiments — and honestly, it's also the nudge that gets the next one started on the evenings I'd otherwise skip it. — Salam
Comments
Join the discussionNo comments yet. Be the first to comment.







