-
Notifications
You must be signed in to change notification settings - Fork 11
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
Some performance tweak #687
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.
It's been a long time since I've looked at this code :) The changes in the fmu.cpp
classes LGTM, I've left a comment in slave_simulator.cpp
.
src/cosim/slave_simulator.cpp
Outdated
values_[i] = iterator->second(values_[i], deltaT); | ||
const auto it = back_refs_.find(ref); | ||
if (it != back_refs_.end()) { | ||
values_[it->second] = entry.second(values_[it->second], deltaT); |
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'm wondering about the need for back_refs_
. Isn't the array index (it->second
here) stored in exposedVariables_.at(ref).arrayIndex
?
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 think you are right, adjusted accordingly.
src/cosim/slave_simulator.cpp
Outdated
@@ -227,14 +227,10 @@ class set_variable_cache | |||
references_.emplace_back(ref); | |||
values_.emplace_back(exposedVariables_.at(ref).lastValue); | |||
} | |||
const auto index = exposedVariables_.at(ref).arrayIndex; |
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.
Since we are talking performance;
exposedVariables_.at(ref)
is called at least two times in this loop. It might make sense to define it as a local variable before line 224.
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.
Thanks, updated accordingly.
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.
LGTM
gsl::span<const value_reference> real_variables, | ||
gsl::span<const value_reference> integer_variables, | ||
gsl::span<const value_reference> boolean_variables, | ||
gsl::span<const value_reference> string_variables) const |
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 was const
removed 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.
Added it back, I think I removed it in the previous version (but not needed in the final version).
# Conflicts: # tests/proxyfmu_integration_unittest.cpp
# Conflicts: # include/cosim/slave.hpp # src/cosim/slave_simulator.cpp # tests/proxyfmu_integration_unittest.cpp
Following updates are for further performance improvement:
1.Additional placement ofLIBCOSIM_NO_FMI_LOGGING
for disabling logging instep_finished_placeholder
step_finished_placeholder
and assignednullptr
to the callback pointer.cosim::slave::get_variables
does not createcosim::slave::variable_values
for each time it's invocation, instead copies data to the argument that is passed to the function.get_variables
, see the updated test cases.set_variable_cache::modfiy_and_get
,std::unordered_map<value_reference, size_t> back_refs_
is used to only update variable values that are subject to modification (via modifier). This avoids unnecessary iteration of all variables in each simulation step.