-
Notifications
You must be signed in to change notification settings - Fork 69
Cache the index of the last accessed polynomial #1712
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
Conversation
} | ||
{ | ||
// Need to use |lower_bound|, not |upper_bound|, because it allows | ||
// heterogeneous arguments. |
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 don't understand this comment (see lower_bound
, upper_bound
).
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.
Removed.
physics/continuous_trajectory.hpp
Outdated
// speeds up the lookup by a factor of 7. This member is atomic because of | ||
// multithreading in the ephemeris, and is mutable to maintain the fiction | ||
// that evaluation has no side effects. Any value in the range of | ||
// |polynomials_| or 0 is correct. |
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.
Comment on the alternative of a std::map<std::thread::id, int>
.
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 am explaining why it works with multithreading. No point in documenting the roads not taken.
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.
For the record: we are trying to optimize a binary search. We know that if polynomials_
is a map the performance is bad. So surely adding a map lookup to try to optimize a binary search doesn't make sense. Also, this really needs to be an atomic
: I started with a shared_mutex
and the cost of acquiring the mutex, even without contention (1 thread) was prohibitive.
In favorable cases this is about 30% faster. In unfavorable cases this is marginally slower, but probably in the noise.
Before:
After: