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

Merged
merged 3 commits into from
Jul 3, 2025

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
@jorisdral jorisdral force-pushed the jdral/lift-8-bytes-restriction branch 2 times, most recently 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
@jorisdral jorisdral force-pushed the jdral/lift-8-bytes-restriction branch from 1a2f622 to a41429e Compare June 30, 2025 15:59
Copy link
Collaborator

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Just a couple comments below.

@jorisdral jorisdral force-pushed the jdral/lift-8-bytes-restriction branch from a41429e to 99ed300 Compare July 3, 2025 14:31
@jorisdral jorisdral enabled auto-merge July 3, 2025 14:31
jorisdral added 3 commits July 3, 2025 16:31
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 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 99ed300 to 58119ff Compare July 3, 2025 14:56
@jorisdral jorisdral added this pull request to the merge queue Jul 3, 2025
Merged via the queue into main with commit de47d16 Jul 3, 2025
30 checks passed
@jorisdral jorisdral deleted the jdral/lift-8-bytes-restriction branch July 3, 2025 16:15
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.

2 participants