perf: reduce per-frame allocations and fix layout bugs#25
Open
Yoshihiko-Ino wants to merge 2 commits into
Open
perf: reduce per-frame allocations and fix layout bugs#25Yoshihiko-Ino wants to merge 2 commits into
Yoshihiko-Ino wants to merge 2 commits into
Conversation
- Node.cs: fix AppendChild/PrependChild calling RemoveChild(this) instead of RemoveChild(node); fix InheritTagsFromParent() ToArray() -> lock+foreach - Node.Style.cs: wrap ComputeStyle() in try-finally to guarantee lock release; fix ToArray() -> lock+foreach (2 places) - Node.Renderer.cs: make DrawDeltaTime/DrawTotalTime static (root-only update); fix BeginOverflowContainer() ToArray() -> lock+foreach - Node.Layout.cs: remove unused System.Collections.Immutable and System.Linq imports - Node.Query.cs: remove unused System.Collections.Immutable import - ObservableHashSet.cs: fix Add() firing ItemAdded on duplicate entries - Layout.cs: fix ContentRect missing Margin offset in ComputeLayout() - Layout.Sizing.cs: remove LINQ double-calculation overwriting manual loop result; remove ToArray() from AnchorToChildNodes.Values and ChildNodes iteration; remove unused imports - Layout.Position.cs: eliminate intermediate List<Node> in GetChildrenWidth/GetChildrenHeight (single-pass loop)
…dification Co-Authored-By: Yoshihiko-Ino <232758239+Yoshihiko-Ino@users.noreply.github.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
Layout.Sizing: ReplacedValues.ToArray()andChildNodes.ToArray()with directforeachover live collections where safe; removed intermediate LINQ expressions that re-computedtotalGapSizeafter the manual loop.Layout.Position: Eliminated intermediateList<Node>allocations inGetChildrenWidth/GetChildrenHeightby folding visible-node filtering and accumulation into a singleforeachloop.Node(query cache): Removed unusedusing System.Collections.Immutableandusing System.Linqimports fromNode.Layout.csandNode.Query.cs.Node.Renderer(Draw loop): Changed_childNodes.ToArray()to a lock-guarded snapshot (lock (_childNodes) { childSnapshot = [.._childNodes]; }) so that the snapshot is taken atomically while still allowingAppendChild/RemoveChildcalls from within a child'sDraw()to proceed without throwingInvalidOperationException.Node.Renderer(overflow container): Replaced_childNodes.ToArray()withlock (_childNodes) { foreach ... }for the position-override pass, which only reads bounds and never modifies the collection.Node(tag inheritance): Replaced unguarded_childNodes.ToArray()inInheritTagsFromParent()with a lock-guarded snapshot.ObservableHashSet: FixedAdd()firingItemAddedeven when the item was already present.Node.Style: WrappedComputeStyle()in try/finally to ensure_isUpdatingStyleand_computeStyleLockare always released.Node: FixedAppendChild/PrependChildcallingRemoveChild(this)instead ofRemoveChild(node).Layout: FixedComputeLayout()omitting the margin offset when computingContentRect.DrawDeltaTime/DrawTotalTimefrom instance tostaticfields.