Cache model.parameterization; try interactive matplotlib backends#1299
Merged
Conversation
Two quick-update performance fixes: 1. Cache `AbstractPriorModel.parameterization` via @functools.cached_property. For MGE models with 40 Gaussians the recursive tree walk triggers 14M function calls (~2.7s). Since the model structure is immutable during a search, caching reduces subsequent calls from 2.7s to 0.05s. 2. live_viewer.py: try interactive matplotlib backends (TkAgg, QtAgg, etc.) before falling back to the inherited Agg backend. The viewer subprocess inherits the parent's Agg (used for headless PNG rendering) but needs a GUI backend to display a window. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Two quick-update performance fixes:
Cache
parameterization—AbstractPriorModel.parameterizationrecursively walks the model tree (14M function calls for 40-Gaussian MGE, ~2.7s). Since the model is immutable during a search,@functools.cached_propertyreduces subsequent calls from 2.7s to 0.05s per quick update.Interactive backend fallback in
live_viewer.py— the viewer subprocess inheritsAggfrom the parent (headless PNG rendering). Now tries TkAgg, QtAgg, etc. before giving up, so the live matplotlib window works on systems with a GUI toolkit installed.API Changes
None —
parameterizationwas already a@property, now@functools.cached_property. Same external interface. The live_viewer backend selection is internal.Test Plan
pytest test_autofit/— 1412 passed, 1 skippedresult_max_lh_info_fromdrops from 2.1s to 0.05s on second call🤖 Generated with Claude Code