Repository navigation
Conversation
pbrubeck
force-pushed
the
pbrubeck/pyop3-axis-forest-getitem-cache
branch
2 times, most recently
from
October 26, 2026 16:55
a6abbac to
71c229e
Compare
AxisForest.getitem tries the indices on each of its trees and skips the trees that they do not match. The trees cache only successful indexing, so every indexing of a forest indexed the mismatched trees again. In Firedrake this happens on every Function.assign or zero on a subset, e.g. each DirichletBC.zero. Cache AxisForest.getitem for static indices, with the same strategy as AbstractNonUnitAxisTree.getitem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pbrubeck
force-pushed
the
pbrubeck/pyop3-axis-forest-getitem-cache
branch
from
October 26, 2026 17:10
71c229e to
ef7f902
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.
Summary
AxisForest.getitemwas trying the indices on each of its trees and skipping the trees that they did not match. The trees were caching only successful indexing, so every indexing of a forest was indexing the mismatched trees again. In Firedrake this was happening on everyFunction.assignorzeroon a subset, e.g. eachDirichletBC.zero.AxisForest.getitemis now cached for static indices, with the same strategy asAbstractNonUnitAxisTree.getitem:Indexing with loop indices is still not cached, so the FIXME about this bottleneck now names loop indices.
Evidence
test_axis_forest_getitem_is_cached(new) indexes a forest twice, and fails if the second indexing indexes any of its trees:After: passes
DirichletBC.zerofor CG2 on a 16×16 mesh (minimum of 200 calls):bc.zero(Function)bc.zero(Cofunction)Merge Danger
Door: two-way
Blast Radius: small
Only indexing of axis forests with static indices changes. The indexed trees are now kept for the lifetime of the forest, as they already were for the lifetime of each tree.
AI assistance: this PR was written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code