Add _fast_cache to Simulation for O(1) repeated variable lookups#436
Open
nikhilwoodruff wants to merge 4 commits intomasterfrom
Open
Add _fast_cache to Simulation for O(1) repeated variable lookups#436nikhilwoodruff wants to merge 4 commits intomasterfrom
nikhilwoodruff wants to merge 4 commits intomasterfrom
Conversation
Adds a flat dict[tuple[str,str], array] at the Simulation level, checked at the top of calculate() before tracer, random seed and _calculate() machinery. Only active when map_to=None and decode_enums=False (the inner-loop hot path). Invalidation mirrors the existing holder cache: - purge_cache_of_invalid_values() removes invalidated entries - delete_arrays() removes the relevant key(s) - clone() gets a fresh empty cache to prevent cross-simulation sharing Uses getattr/hasattr guards so StubSimulation and other test subclasses that bypass __init__ work without modification. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
Good catch — the fast path was skipping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a flat
dict[(variable_name, str(period)), array]at theSimulationlevel, checked at the very top ofcalculate()before the tracer,np.random.seedand the full_calculate()machinery. Only active whenmap_to=Noneanddecode_enums=False(the inner-loop hot path used by formulas calling dependencies).Invalidation mirrors the existing holder cache:
purge_cache_of_invalid_values()removes invalidated entries,delete_arrays()clears the relevant key(s), andclone()gets a fresh empty cache so parent and clone simulations don't share state.getattr/hasattrguards mean subclasses likeStubSimulationthat bypass__init__work without modification.