-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
FindFileInRange: devirtualize comparator and add prefix cache #10646
base: main
Are you sure you want to change the base?
FindFileInRange: devirtualize comparator and add prefix cache #10646
Conversation
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.
Interesting! Do you have db_bench results that you can share? Also, what is the performance impact of the comparator devirtualization specifically? Wondering if that can be applied to other places, like DataBlockIter
.
// Find File in LevelFilesBrief data structure | ||
// Within an index range defined by left and right | ||
int FindFileInRange(const InternalKeyComparator& icmp, | ||
const LevelFilesBrief& file_level, | ||
const Slice& key, | ||
uint32_t left, | ||
uint32_t right) { | ||
if (IsForwardBytewiseComparator(icmp.user_comparator())) { |
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.
The comparator is not a mutable option, so is it worth doing this check once and reuse the result?
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 checks data field opt_cmp_type_
, it is just a trivial uint8_t
compare.
mid = (lo + hi) / 2; | ||
exact_search: | ||
#ifdef __GNUC__ | ||
__builtin_prefetch(a[mid].largest_key.data_); |
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.
Not sure how effective this prefetch will be, since we use it right away.
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.
before the memcmp
accessing a[mid].largest_key.data_
, there are enough other independent instructions, so it is worth to prefetch.
We generated flame graphs, CPU time of |
This PR is based on #10645.
If comparator is BytewiseComparator or ReverseBytewiseComparator: