Eliminate XmlChildNodes allocations in GetXmlNodeInnerContents#13509
Merged
JanProvaznik merged 2 commits intoApr 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces GC pressure in Utilities.GetXmlNodeInnerContents by avoiding repeated XmlNode.ChildNodes accesses (which allocate XmlChildNodes wrappers on .NET Framework) and using allocation-free FirstChild/NextSibling checks instead.
Changes:
- Replaces
node.ChildNodes.Count == 1checks withfirstChild.NextSibling == nullto avoid per-callXmlChildNodesallocations. - Caches
node.FirstChildand simplifies the “no children / single whitespace child / single text or CDATA child” fast paths.
Member
|
running experimental insertion to see impact on perf metrics |
danmoseley
approved these changes
Apr 12, 2026
Member
|
https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/727231 impact visible on speedometer thanks |
JanProvaznik
approved these changes
Apr 13, 2026
This was referenced Apr 15, 2026
This was referenced Jun 10, 2026
This was referenced Jun 11, 2026
Merged
Open
Open
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.
🤖 AI-Generated Pull Request 🤖
This pull request was generated by the VS Perf Rel AI Agent. Please review this AI-generated PR with extra care! For more information, visit our wiki. Please share feedback with TIP Insights
Issue:
Utilities.GetXmlNodeInnerContentsaccessesnode.ChildNodestwice to checkCount == 1.In .NET Framework,
XmlNode.ChildNodescallsnew XmlChildNodes(this)on every access — it never caches — so each call produces 2 throwaway heap allocations.This method is called for every property and metadata element during evaluation, making it a significant source of GC pressure during solution load.
Allocation sites (
TypeAllocated!System.Xml.XmlChildNodes, ~86% of sampled allocations):Callers on hot path as per Perfwatson traces:
Issue type: Avoid allocating wrapper objects when allocation-free alternatives exist on the same API surface.
Proposed fix: Replace
node.ChildNodes.Count == 1withnode.FirstChild.NextSibling == null— a simple pointer check that answers the same question ("is there exactly one child?") with zero allocations. CacheFirstChildin a local and split the compoundifinto clear separate checks. This is a direct semantic equivalence (FirstChild == null↔!HasChildNodes,NextSibling == null↔Count == 1), internal-only, and produces identical results for all edge cases.Best practices wiki
See related failure in PRISM
ADO work item