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
Avoid doing extra TLS lookups in FunctionParser. #13745
Conversation
Would you mind explaining some more what changed? I see that you introduced another data structure but which part is actually responsible for reducing the number of calls to lock the mutex? |
* std::is_copy_constructible gives the wrong answer for containers with | ||
* non-copy constructible types (e.g., std::vector<std::unique_ptr<int>>). | ||
* Work around that problem by defining our own explicitly uncopyable | ||
* per-thread data class (instead of, e.g., using std::pair). | ||
* | ||
* We define exactly one per-thread data structure to avoid locking and | ||
* unlocking the TLS data lookup more than once per function call. | ||
*/ | ||
mutable Threads::ThreadLocalStorage<std::vector<double>> vars; | ||
struct ParserData | ||
{ | ||
ParserData() = default; | ||
|
||
ParserData(const ParserData &) = delete; | ||
|
||
/** | ||
* Scratch array used to set independent variables (i.e., x, y, and z) | ||
* before each muParser call. | ||
*/ | ||
std::vector<double> vars; | ||
|
||
/** | ||
* muParser implementations. | ||
*/ | ||
std::vector<std::unique_ptr<internal::muParserBase>> parsers; | ||
}; |
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.
Isn't this the exact same class as for the function_parser.h
file?
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. I need to move some more functions into mu_parser_internal.h
- if its OK with you I would like to do that refactoring in the next PR.
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.
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.
Apart from Wolfgang's comment, this looks good to me. Thank you for pointing out the relevant changes!
While we are at it, get rid of the calls to begin_raw() and end_raw() (they are deprecated).
Thanks for fixing this and to @masterleinad for doing the merge. I'm at the ASPECT hackathon, it's been a busy week. |
Avoid doing extra TLS lookups in FunctionParser.
Fixes #13578 to the largest extent possible right now. There may be better thread locking and unlocking strategies but by moving some things around I can evaluate simple expressions about 3x faster.
While we are at it, get rid of the calls to begin_raw() and end_raw() (they are deprecated).