Repository navigation
perf(model): write solve results instead of rebuilding DataArrays - #1035
Open
olivier-lacroix wants to merge 2 commits into
Open
olivier-lacroix wants to merge 2 commits into
olivier-lacroix wants to merge 2 commits into
Conversation
olivier-lacroix
force-pushed
the
perf/assign-result-arrays
branch
from
October 20, 2026 03:16
6319d3d to
a7c3668
Compare
olivier-lacroix
marked this pull request as ready for review
October 20, 2026 03:19
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
Author
|
Thx @FabianHofmann ! |
olivier-lacroix
force-pushed
the
perf/assign-result-arrays
branch
from
October 24, 2026 02:12
d177467 to
341f11a
Compare
`Model.assign_result` built a `DataArray` per variable and constraint and let the public setters align and merge it against the stored fields. Writing the arrays straight in is enough: the shape and coordinates are already correct. At 20 variables and 20 constraints over 2000 timesteps, `assign_result` drops from 8.8 ms to 1.0 ms. Co-Authored-By: Claude Code <noreply@anthropic.com>
olivier-lacroix
force-pushed
the
perf/assign-result-arrays
branch
from
October 25, 2026 03:32
341f11a to
89c4c83
Compare
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.
A minor performance improvement, discovered while profiling some LP models.
Note
The following content was generated by AI.
What
Model.assign_resultbuilds aDataArrayper variable and per constraint, then lets the public setters merge it into each container's dataset. After a solve the shape and coordinates are already correct, so writing the arrays into a shallow copy is enough.common.set_data_varwrites one data variable without xarray's merge pass.Variable._assign_solutionandConstraint._assign_dualuse it.Model.assign_resultcalls both.The public
Variable.solutionandConstraint.dualsetters are unchanged, so nothing else moves.Benchmark
Scenario: 20 variables and 20 constraints over 2000 timesteps, median of 10
assign_resultcalls.assign_resultReproduce
AI assistance
Drafted with Claude Code: the implementation and the measurement. Reviewed by hand before opening.