-
Notifications
You must be signed in to change notification settings - Fork 170
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 IntegerNode::find_first_local #7772
Conversation
If you are just testing one element, use simple compare instead of leaf->find_first. This will speed up queries where secondary nodes are IntegerNodes.
Pull Request Test Coverage Report for Build jorgen.edelbo_285Details
💛 - Coveralls |
PS: we need this for integer compression too. |
src/realm/query_engine.hpp
Outdated
@@ -425,6 +425,17 @@ class IntegerNode : public IntegerNodeBase<LeafType> { | |||
|
|||
size_t find_first_local(size_t start, size_t end) override | |||
{ | |||
TConditionFunction c; |
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.
All our operators shouldn't have anything going on in the constructor, but can you move this to inside the scope where it is used so that one isn't constructed/destructed when it isn't used? (Hopefully the compiler knows that this is a no-op but you never know)
src/realm/query_engine.hpp
Outdated
@@ -425,6 +425,17 @@ class IntegerNode : public IntegerNodeBase<LeafType> { | |||
|
|||
size_t find_first_local(size_t start, size_t end) override | |||
{ | |||
TConditionFunction c; | |||
if (end - start == 1) { |
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.
why not move the end - start == 1
case into the Array's find_first method itself? Then all call sites will benefit from the optimization.
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.
Yes - that might actually be a better idea
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.
Please provide some benchmarks to show the benefit of the change. Is it for queries such as: !(int > 23)
?
Pull Request Test Coverage Report for Build jorgen.edelbo_286Details
💛 - Coveralls |
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.
Great! Could be worth adding a benchmark, and noting which queries could expect to have improved performance in the changelog.
return to_size_t(state.m_state); | ||
else | ||
return not_found; | ||
return static_cast<size_t>(state.m_state); |
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.
nit: QueryStateFindFirst.m_state is already a size_t, so no cast is necessary here.
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.
I hate being caught in this - but it was copied from somewhere else :-)
I will fix this later
Some benchmark improvement:
it is queries like "age > 20 && height > 200" that benefit from this. |
If you are just testing one element, use simple compare instead of leaf->find_first. This will speed up queries where secondary nodes are IntegerNodes.
What, How & Why?
☑️ ToDos
bindgen/spec.yml
, if public C++ API changed