fix: invalidate each ancestor once instead of 2^depth times - #181
Merged
Merged
Conversation
UIElementBase.Invalidate() called Parent.Invalidate() and also raised Invalidated, which every container subscribes to for its children, so each level passed the invalidation up twice and the root saw 2^depth calls. Keep the event subscription as the single propagation path. Fixes #148 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jn27sjy5Z1Sbi1aZaAJDgj
|
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.



Fixes #148
What changed
UIElementBase.Invalidate()passed the change upward twice: it calledParent?.Invalidate()directly, and it raisedInvalidated, whichUIContainerBasesubscribes to for every child it adopts. Each level doubled the count, so a leaf 16 levels deep invalidated the root 65,536 times.This keeps the event subscription as the one propagation path and removes the direct
Parent?.Invalidate()call. I kept the subscription rather than theParentcall because it follows actual membership in_childrenand covers anyIUIElementimplementation, not onlyUIElementBase. Every built-in container (StackPanel,BorderElement) adopts children throughUIContainerBase.AddChild, so nothing loses notification.The
IUIElement.Invalidate()doc comment now says the parent is notified through the event.Tests
AChangeNestedManyLevelsDeepInvalidatesTheRootOnce: the repro from the issue (a leaf 16 levels deep), asserting the root fires once.AChangeInvalidatesEachAncestorOnce: an intermediate container and the root each fire once.Both tests fail with the fix reverted (root count 65536, middle count 2) and pass with it. The full
TUI.Testsuite passes: 219/219.🤖 Generated with Claude Code
https://claude.ai/code/session_01Jn27sjy5Z1Sbi1aZaAJDgj
Generated by Claude Code