-
Notifications
You must be signed in to change notification settings - Fork 163
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
Optimize sort followed by limit #6941
Conversation
aaf922e
to
25e7ba8
Compare
If the limit is much smaller than the total size of the TableView, then it is faster to make a sorted insert into a vector that is kept at the limit size.
25e7ba8
to
19cc731
Compare
Once we do #6933 we should be able to optimize this further by only inserting the limit number of elements into the vector in the first place instead of having an extra buffer like you do here. Given that we expect future optimizations, could you please move the benchmark out of the test and into benchmark-common-tasks so that we can track this case over time. If you could post that benchmark's results compared to current master, I'd also be curious to see what kind of improvement this actually is 😄 |
src/realm/sort_descriptor.cpp
Outdated
IndexPairs buffer; | ||
buffer.reserve(limit + 1); | ||
for (auto& elem : v) { | ||
auto it = std::lower_bound(buffer.begin(), buffer.end(), elem, predicate); |
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.
If std::ref()
is doing something useful in the std::sort()
case then it will here too (it makes it so that the predicate is not copied when it's passed to the algorithm).
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.
👍
@ironage I am not sure how we can avoid the buffer. We cannot clear the buffer that holds the elements we should sort.
|
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.
👍
If the limit is much smaller than the total size of the TableView, then it is faster to make a sorted insert into a vector that is kept at the limit size.
What, How & Why?
☑️ ToDos