call _get_shunts once not twice#306
Closed
luke-kiernan wants to merge 1 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes Y-bus branch entry computation by avoiding repeated shunt getter calls during matrix assembly, reducing time spent in shunt retrieval on profiling.
Changes:
- Replace per-side
_get_shunt(br, node)calls with a single_get_shunts(br)call returning both end shunts. - Cache
get_g(br)/get_b(br)results within_get_shuntsto avoid repeated getter overhead.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
447
to
+449
| Y12 = -Y_l | ||
| Y21 = Y12 | ||
| Y22 = Y_l + _get_shunt(br, :to) | ||
| Y22 = Y_l + shunt_to |
Collaborator
Author
There was a problem hiding this comment.
Pre-existing issue. But yeah, it is strange that we only check Y11 and Y_l, not Y22. @m-bossart is there a reason for this?
Contributor
Performance ResultsPrecompile Time
Execution Time
|
Collaborator
Author
|
Ok the perf measurements aren't bearing this out--I took Claude's word for it--so I'm going to close this. The root problem is the type instability in the getters, which will go away after the units fixes anyway |
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.
I ran
PProfon assembling the y bus matrix for unrelated reasons and the total time inside_get_shuntswas surprisingly high. Fetching the values for both "from" and "to" sides in a single call helps.Aside: I suspect the cost is primarily due to the type instability in the getters, which will be resolved by my unit fixes.