-
Notifications
You must be signed in to change notification settings - Fork 14
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 vectorized #376
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scooletz
added
🐌 performance
Perofrmance related issue
💥Breaking
The change introduces a storage breaking change.
labels
Jul 24, 2024
Scooletz
force-pushed
the
slotted-array-vectorized
branch
from
July 25, 2024 16:13
39ad9a8
to
abfb04b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the way
SlottedArray
uses vectorized search.Previously, it was using the
Span.IndexOf
over a set of slots. This resulted in 2x more data being searched through, with potential (but quite unlikely) false positive hits when theSlot.Raw
was equal to the hash. Additionally, when hash collision occurred, it requires multiple calls to theSpan.IndexOf
to move the search across the map.This PR makes a change by aligning
SlottedArray
to the biggest vector allowed on the given platform,Vector256
forx64
andVector128
forARM
. It does it by introducing chunks of size of the vector that describe the hashes and the raw part providing the markers and the pointer in page. For x64, this requires to allocate 32 bytes for hashes + 32 bytes for raw = 64 bytes of chunk. There's no other overhead beside some slots potentially not being used (max 60 bytes). This approach allows to scan hashes in a nicely vectorized way without dealing with false positives and checks whether a given value is at a hash offset or not. Then, if the search is not done, jump over the vector of Slots to the next one.The advantages are the following:
The vector alignment has been tested on x64, but showed no positive impact in benchmarks
TODO List
Vector128
forARM
and others (throws on scalar)odd nibble path(no impact on construction, rather on Prepare/Unprepare)path longer than 4 so that the(this will compare equals only)NibblePath
comparison happensrestore defragmentation benchmark(not needed)consider materializing the(left for future work)NibblePath
inTryFind
or before so that the comparison above works as expectedBenchmarks
The new benchmarks, based on aligned memory, to make them truly comparable show great results. Especially, if the search is not found in the initial keys but requires more iterations.
TryGet
Before
After
TryGet_With_Hash_Collisions
Before
After
SlottedArray
upgraded design