Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is _BTree defaultLeafCapacity correct? #257

Open
jessegrosjean opened this issue Dec 23, 2022 · 1 comment
Open

Is _BTree defaultLeafCapacity correct? #257

jessegrosjean opened this issue Dec 23, 2022 · 1 comment
Labels
bug Something isn't working SortedCollections

Comments

@jessegrosjean
Copy link

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 jessegrosjean added the bug Something isn't working label Dec 23, 2022
@lorentey
Copy link
Member

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SortedCollections
Projects
None yet
Development

No branches or pull requests

2 participants