Improve caching of equivalent variables in analyser model.#1389
Conversation
agarny
left a comment
There was a problem hiding this comment.
Looks good and definitely faster! Nice!
AnalyserModel::AnalyserModelImpl::buildEquivalentVariablesCache() should probably be called in AnalyserModel::areEquivalentVariables() (if the cache hasn't already been built), but having said that we know that the analyser is going to call AnalyserModel::areEquivalentVariables() many times, so I guess it's fine to call AnalyserModel::AnalyserModelImpl::buildEquivalentVariablesCache() upon retrieving the analyser model?
agarny
left a comment
There was a problem hiding this comment.
This looks. "Just" some nitpicking.
| * because an @ref AnalyserModel always refers to a static version of a | ||
| * @ref Model. However, this might break if a @ref Model is modified after it | ||
| * has been analysed. | ||
| * The function utilizes caching which is constructed during the model |
There was a problem hiding this comment.
"utilises", not "utilizes".
| * has been analysed. | ||
| * The function utilizes caching which is constructed during the model | ||
| * analysis phase (@ref Analyser::analyseModel). The cache may become | ||
| * out-of-date if the model is changed after the model has been analysed. |
There was a problem hiding this comment.
"out of date", not "out-of-date" since it is not followed by a noun.
| return (first == other.first) & (second == other.second); | ||
| if (it == mEquivalentVariableCache.end()) { | ||
| mEquivalentVariableCache[x] = x; | ||
| return x; |
There was a problem hiding this comment.
I would put an empty line before thereturn statement (to make things stand out more).
| } | ||
| } | ||
|
|
||
| void AnalyserModel::AnalyserModelImpl::buildEquivalentVariablesCache(const ComponentPtr &component) |
There was a problem hiding this comment.
I would put this method before the previous one (at line 51), to respect the order in which they are declared in src/analysermodel_p.h.
There was a problem hiding this comment.
Do we really want to put some actual code in a header file? I am talking about findRootAddress() and uniteEquivalentAddresses().
| struct VariableKeyPair | ||
| std::unordered_map<uintptr_t, uintptr_t> mEquivalentVariableCache; | ||
|
|
||
| uintptr_t findRootAddress(uintptr_t x) |
There was a problem hiding this comment.
Would rename this method to findVariableAddress(). I am not sure what is meant by "root" here.
| } | ||
|
|
||
| hash ^= pair.second + 0x9e3779b9 + (hash << 6) + (hash >> 2); | ||
| void uniteEquivalentAddresses(uintptr_t x, uintptr_t y) |
There was a problem hiding this comment.
I would rename this method to uniteEquivalentVariableAddresses() to be consistent with line 51.
There was a problem hiding this comment.
I imagine that this file (as well as act-end-2-end-input.txt and act-payload.json) were used for profiling? If so, then they should be removed. If not, then they should somehow be modified so that they are neither specific to your environment nor to a specific version of libCellML.
Uh oh!
There was an error while loading. Please reload this page.