Hacker News new | ask | show | jobs
by infamouscow 12 days ago
B+tree were designed around optimized IO in the era of magnetic storage, they're inherently cache-friendly. Skiplists are the same thing as a b+tree but the structure is inverted, which makes skiplists more to concurrent writer-friendly than b+trees. Different tradeoffs.
3 comments

The data structure is not a pure B+tree. They also strip common key prefix for node elements and store 4 bytes of remaining key data together with a pointer to the children to avoid key lookup in many cases. Plus they tune node sizes to match jemalloc allocation classes to minimize allocation overhead. I am not sure with such focus on cache friendliness the advantage of skip lists for writes still holds as they will still have more cache misses even on inserts.
But more cache misses, due to the variable pointer length structure.

That cost varies from chip generation to generation, but it does seem to be the case that b trees win in more generations than they lose.

Yep. I’ve implemented b trees and skip lists a few times. I find skip lists to be a little easier to implement. But b trees seem to perform ~20% faster. I can’t think of any good reasons to use skip lists instead of b trees in high performance code.
Well, avoiding locks is one reason, since lockfree skiplists are fairly simple but lockfree b-trees essentially don’t exist. Concurrent b-trees using locks are pretty well-understood though and perform well.