swift-collections icon indicating copy to clipboard operation
swift-collections copied to clipboard

Is _BTree defaultLeafCapacity correct?

Open jessegrosjean opened this issue 2 years ago • 1 comments

I assume I'm wrong here, asking for education mostly :)

The code looks like this:

/// Recommended node size of a given B-Tree
@inlinable
@inline(__always)
internal static var defaultLeafCapacity: Int {
  #if DEBUG
  return 5
  #else
  let capacityInBytes = 2000
  return Swift.min(16, capacityInBytes / MemoryLayout<Key>.stride)
  #endif
}

From my reading the max leaf capacity is 16? Is that right? I would expect (without really understanding much of the code here) performance to be better if leaves could contain more then 16 elements when element size is small.

jessegrosjean avatar Dec 23 '22 13:12 jessegrosjean

Hm, I think so -- it looks like this should use Swift.max, not Swift.min. The capacity in bytes also looks a little low to me -- we'll probably want to increase it to something like 16kiB or so as part of the performance work that'll precede its release.

(Beware, the SortedCollections module is not yet ready for production use, and its API may see source-breaking changes before it ships.)

lorentey avatar Dec 23 '22 22:12 lorentey