Skip to content

Lift the restriction of minimum 8-byte keys for the compact index #746

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jorisdral
Copy link
Collaborator

@jorisdral jorisdral commented Jun 2, 2025

We maketopBits64 safe for raw bytes of size less than 8. When the size of the raw bytes is less than 8, then a fallback method is used that is likely slower. When the size of the raw bytes is 8 or higher, then an
additional integer comparison is made, but this has very little impact on
performance, which I verified using micro-benchmarks. The upside to making the
function safe for any input raw bytes is that the API and test generators become
simpler, because there is one fewer constraint to satisfy: the minimum size of 8
bytes for serialised keys.

Now that topBits64 is fully safe, remove the 8-byte key constraint when using
the compact index. Instead, the config option for the index type includes a hint
not to use the compact index if keys are too small, because that will lead
to bad performance.

@jorisdral jorisdral self-assigned this Jun 2, 2025
When the size of the raw bytes is less than 8, then a fallback method is used
that is likely slower. When the size of the raw bytes is 8 or higher, then an
additional integer comparison is made, but this has very little impact on
performance, which I verified using micro-benchmarks. The upside to making the
function safe for any input raw bytes is that the API and test generators become
simpler, because there is one fewer constraint to satisfy: the minimum size of 8
bytes for serialised keys.
@jorisdral jorisdral force-pushed the jdral/lift-8-bytes-restriction branch from 2bb714c to 3e8d2c3 Compare June 3, 2025 09:40
jorisdral added 2 commits June 3, 2025 11:44
Now that `topBits64` is fully safe, remove the 8-byte key constraint when using
the compact index. Instead, the config option for the index type includes a hint
not to use the compact index if their keys are too small, because that will lead
to bad performance.
A small bug related to the merge schedule and union levels was unearted after
recent changes to key generators for the state machine tests.

```
❯ cabal run lsm-tree-test -- --quickcheck-replay="(SMGen 13447116701882578385 16048829213438376903,35)"   -p '$NF=="propLockstep_RealImpl_MockFS_IO"'
lsm-tree
  Test.Database.LSMTree.StateMachine
    propLockstep_RealImpl_MockFS_IO: FAIL (28.54s)
      *** Failed! Assertion failed (after 1 test and 196 shrinks):

      ...

1 out of 1 tests failed (28.54s)
```

The bug was that the last level was always removing `Delete` entries even if
there was union level. This is now fixed.
@jorisdral jorisdral force-pushed the jdral/lift-8-bytes-restriction branch from 3e8d2c3 to 1a2f622 Compare June 3, 2025 09:45
@jorisdral jorisdral marked this pull request as ready for review June 3, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant