Skip to content

Commit

Permalink
Simplify cache invalidation as spiral error occur
Browse files Browse the repository at this point in the history
  • Loading branch information
guillett committed Feb 5, 2024
1 parent a6c5da3 commit d641829
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions openfisca_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,12 @@ def invalidate_cache_entry(self, variable: str, period):
self.invalidated_caches.add(Cache(variable, period))

def invalidate_spiral_variables(self, variable: str):
# Visit the stack, from the bottom (most recent) up; we know that we'll find
# the variable implicated in the spiral (max_spiral_loops+1) times; we keep the
# intermediate values computed (to avoid impacting performance) but we mark them
# for deletion from the cache once the calculation ends.
count = 0
for frame in reversed(self.tracer.stack):
self.invalidate_cache_entry(str(frame["name"]), frame["period"])
if frame["name"] == variable:
count += 1
if count > self.max_spiral_loops:
break
invalidate_entries = False
for frame in self.tracer.stack:
if not invalidate_entries and frame["name"] == variable:
invalidate_entries = True
if invalidate_entries:
self.invalidate_cache_entry(str(frame["name"]), frame["period"])

# ----- Methods to access stored values ----- #

Expand Down

0 comments on commit d641829

Please sign in to comment.