Repository navigation
Read ReturnDataView/ExpDataView field shapes on first access - #3526
Open
FFroehlich wants to merge 1 commit into
Open
FFroehlich wants to merge 1 commit into
FFroehlich wants to merge 1 commit into
Conversation
`ReturnDataView.__init__` built a dict with the shapes of all array fields, reading about 35 attributes of the SWIG-wrapped `ReturnData` and allocating about 40 GC-tracked objects per view, whether or not a field was read. For `run_simulations` with thousands of conditions, this dominated the time to construct the views and triggered frequent garbage collections. `ExpDataView` did the same for its fields. `_field_dimensions` is now a class attribute that maps each field to a function of the wrapped object returning the field's shape. It is evaluated when the field is first accessed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/quirky-margulis-928f12 #3526 +/- ##
==============================================================
Coverage 80.30% 80.31%
==============================================================
Files 331 331
Lines 23438 23440 +2
Branches 1631 1631
==============================================================
+ Hits 18823 18825 +2
Misses 4609 4609
Partials 6 6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Stacked on #3525.
ReturnDataView.__init__built a dict with the shapes of all array fields. For every view, that read about 35 attributes of the SWIG-wrappedReturnDataand allocated about 40 GC-tracked objects, whether or not any field was read.ExpDataViewdid the same for its fields._field_dimensionsis now a class attribute that maps each field to a function of the wrapped object returning the field's shape. It is evaluated when the field is first accessed, and the resulting array is cached as before. Constructing a view is now just a type check plus setting the pointer and an empty cache.Shapes are now read at the first access of a field rather than at view creation. So an
ExpDataViewsees changes to theExpDatamade before a field is first read; before, this failed with a reshape error. A new test covers this.Measurements
Setup: Python 3.13, a 2-state model,
run_simulationswith 9169ExpDatas and forward sensitivities, 6 calls (55k views). Afterwardsllh,sllhandFIMare read from every result.llh,sllh,FIMWith 12M long-lived GC-tracked objects in the process (standing in for a large PEtab problem), view construction went from 2.29 s to 0.03 s, and GC time from 1.32 s to 0.82 s. One full collection remains, triggered by the earlier allocations of the large heap.
This is the cost that the profile in #3510 (comment) charged to
XArrayFactory.__init__(about 11 s for 18,338 views). See #3525 for why cProfile charged it there.🤖 Generated with Claude Code