Cache values in the RC system for speed #1579
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and context:
Previously, repeated
rc.get
calls could take significant time. I noticed this when profiling. However, I'm not sure where the particular calls are in our code (I know they're in the simulatorstep
function somewhere, either here or innengo-loihi
).My solution was to cache things in our
_RC
class when they're first used. I've also configured the cache to get cleared (for the specific value) whenrc.set
is called, or for all values if we clear/reload the RC file. This should ensure that users can still userc.set
or load their own RC file before making networks/simulators/etc., and the new settings will be used.We should probably go through and make sure when we make operators for a simulator, they're not calling into
rc
repeatedly (they should load therc
value once when they make the operator, and then re-use the value). From what I can tell, the place where it is actually happening is inSupportDefaultsMixin.__setattr__
, where we check if we're using simplified exceptions. It might be a little tricky to cache things there, because we don't want to cache to early (e.g. if some config setting is set when Nengo is imported) and have a later user change of the value not have an effect. This is why I've taken the current approach for now.How has this been tested?
I've ran the test suite. We'll need some unit testing to ensure full coverage.
How long should this take to review?
Types of changes:
Checklist:
Still to do: