-
Notifications
You must be signed in to change notification settings - Fork 11
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
Slotted array search and insert optimizations #370
Conversation
@@ -62,7 +62,8 @@ public bool TrySet(in NibblePath key, ReadOnlySpan<byte> data) | |||
|
|||
private bool TrySetImpl(ushort hash, byte preamble, in NibblePath trimmed, ReadOnlySpan<byte> data) | |||
{ | |||
if (TryGetImpl(trimmed, hash, preamble, out var existingData, out var index)) | |||
var index = TryGetImpl(trimmed, hash, preamble, out var existingData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better that it would return a bool
and index
would be out param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done before. As #369 showed it cuts off 40 bytes from 800 byte long method without impact on the call sites that need to compare it anyway. Follows IndexOf
and others low lvl method in BCL.
This PR tries to address the crux of the db performance issues,
SlottedArray
component that is visible in both, inserts and gets from the database. It does it in the following way:TryGetImpl
changed from bool returning to index returning results in shorter code (~40 bytes)IsDeleted
checkis not needed and can be removed saving one bool check and reducing the size furtherMarkAsDeleted
, when marking the entry as deleted changes its hash (to simple ~hash) so that it will no longer hit the search. See theSet_And_Delete
benchmark below. This is 💥 for both sets and gets as they use this function heavily. The gains are tremendous.Benchmarks
Selected benchmarks used to check the speed.
Before
After