Repository navigation
Conversation
Parameter, ParameterAtInstant, ParameterNode and ParameterScale clones deep-copied their metadata. On policyengine-us one tree clone makes 1,257,541 ParameterAtInstant clones, and those deep copies were most of the cost of TaxBenefitSystem.clone(). Each clone now gets its own metadata dict (copy.copy, so None and dict subclasses behave as before) holding the source's values. Top-level edits stay on their side; a nested value must be replaced, not edited in place. interpolate_parameters was the only writer that edited a nested value after a clone exists (TaxBenefitSystem.__init__ clones the tree into parameters.baseline before interpolating), so it now replaces the interpolation dict it marks complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
propagate_parameter_metadata hands each descendant the node's own interpolation dict, so marking it complete in place skipped every child after the first. Replacing the dict fixes that too; no PolicyEngine country model uses propagated interpolation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
WIP. Benchmarks on policyengine-us and the full Core suite are running. Numbers will be filled in below.
Problem
Parameter.clone,ParameterAtInstant.clone,ParameterNode.cloneandParameterScale.cloneeach callcopy.deepcopy(self.metadata). On policyengine-us one tree clone makes 1,257,541ParameterAtInstantclones, and these deep copies are most of the cost ofTaxBenefitSystem.clone(). Every reform build, behavioural-response measurement andSimulation.clone()in policyengine-us pays that cost.Change
copy.copy, holding the source's values.NonestaysNoneand dict subclasses keep their type, as before.interpolate_parametersreplaces theinterpolationdict it marks complete instead of editing it.Plan
TaxBenefitSystem.clone()on policyengine-us (time, peak RSS)🤖 Generated with Claude Code