Repository navigation
Improve immutable map index performance: sort point IDs, binary search and deleted flags - #5072
Merged
Merged
Conversation
Closed
6 tasks done
timvisee
marked this pull request as ready for review
September 12, 2024 18:30
xzfc
reviewed
Sep 13, 2024
6 tasks done
xzfc
approved these changes
Sep 13, 2024
Member
There was a problem hiding this comment.
LGTM.
I think it's also possible to implement another approach:
enum PointsSet {
// Up to three points could be stored directly within this type
Inline([u32; 3]),
// 4..24 points could be stored in value_to_points_container.
// Do a linear search during deletion, but for up to 24 elements it would be neglectible.
Container(Range<u32>),
// Greater amount of points stored in a heap-allocated structure.
// The memory overhead should only be a concern for small amount of points which is covered by previous variant.
// Enables `O(log(n))` deletion times.
BTreeSet(BTreeSet<u32>),
}
6 tasks done
Member
Author
Definitely something to investigate. Out of curiosity, why did you choose 3? Is it because it's the maximum size without growing the enum in terms of memory? I'd vote to explore this idea in a separate PR. Here I tried to keep everything intact on purpose. |
Member
Yep, |
generall
approved these changes
Sep 16, 2024
Member
This structure takes 32 bytes in my test |
generall
force-pushed
the
immutable-map-index-deleted-flags
branch
from
September 16, 2024 12:49
93dad46 to
e6fdf80
Compare
timvisee
added a commit
that referenced
this pull request
Sep 17, 2024
…h and deleted flags (#5072) * Improve immutable map index, sort values, binary search, deleted flags * Add struct for value to points range and count
Merged
6 tasks done
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Our immutable map index appears to be very slow if we have a huge number of points but very few distinct values.
The problem is in a linear search when we're trying to delete an item. This may become very hot when deleting a lot of point duplicates on start.
I've improved on this by sorting the list of point IDs so we can do a binary search rather than a scan. This PR also implements deleted flags to not remove point IDs from the middle of this list anymore.
My test collection has a segment of about 750k points with 5 keyword indices having just 2 distinct values. This segment is duplicated to get 750k duplicates.
This is how long it takes when loading
I've also implemented an alternative. It doesn't have deleted flags but removes point IDs from the list. It deletes and shifts remaining items. It is slower at 86 seconds (#5070).
All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --all --all-featurescommand?