[Efficiency Improver] perf: reduce allocations in BFSTestNodeVisitor path tracking and WrappedName building#7836
Merged
Evangelink merged 3 commits intoApr 27, 2026
Conversation
…teWrappedName - Replace StringBuilder in the BFS queue with string, eliminating one StringBuilder allocation per test node during tree traversal. Each node's full path is now an immutable string shared directly with child nodes as their base path. - Replace HashSet<PlatformTestNodeUid> with HashSet<string> for UID filter lookups. This avoids allocating a temporary PlatformTestNodeUid wrapper object on every node lookup in the HashSet. - Simplify CreateWrappedName in TestArgumentsManager to a conditional string.Concat, removing a StringBuilder allocation per argument entry. Proxy metric: heap allocations per test node during BFS traversal. Before: 1 StringBuilder + 1 string per node (path) + 1 PlatformTestNodeUid per node (filter lookup). After: 1 string per node (path), no PlatformTestNodeUid per lookup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces heap allocations in MSTest.Engine’s test-node discovery/execution pipeline by simplifying per-node path tracking in BFSTestNodeVisitor and by removing StringBuilder usage in argument display-name wrapping.
Changes:
- Replace per-node
StringBuilderpath propagation inBFSTestNodeVisitorwith immutablestringpath tracking. - Avoid per-lookup
PlatformTestNodeUidwrapper allocations by switching UID filter membership checks toHashSet<string>. - Simplify
TestArgumentsManager.CreateWrappedNameto usestring.Concatinstead ofStringBuilder.
Show a summary per file
| File | Description |
|---|---|
| src/Adapter/MSTest.Engine/Engine/BFSTestNodeVisitor.cs | Removes per-node StringBuilder allocations in BFS traversal and reduces UID-filter lookup allocations by using string values directly. |
| src/Adapter/MSTest.Engine/Engine/TestArgumentsManager.cs | Removes StringBuilder allocation from wrapped-name formatting for argument fragments. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
This was referenced Apr 26, 2026
…deVisitor Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/c99d957f-6c20-4942-988b-5c1977ecef1d Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
…nd cache PathSeparator as string field Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/eb488e40-99da-4224-81ee-95f9c0e4dc4b Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
JanKrivanek
approved these changes
Apr 27, 2026
Member
|
Btw. PR description got likely half eaten out |
This was referenced Apr 28, 2026
2 tasks
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.
Replace StringBuilder in the BFS queue with string, eliminating one StringBuilder allocation per test node during tree traversal. Each node's full path is now an immutable string shared directly with child nodes as their base path.
Replace HashSet with HashSet for UID filter lookups. This avoids allocating a temporary PlatformTestNodeUid wrapper object on every node lookup in the HashSet.
Simplify CreateWrappedName in TestArgumentsManager to a conditional string.Concat, removing a StringBuilder allocation per argument entry.
Proxy metric: heap allocations per test node during BFS traversal. Before: 1 StringBuilder + 1 string per node (path) + 1 PlatformTestNodeUid
per node (filter lookup).
After: 1 string per node (path), no PlatformTestNodeUid per lookup.
Fixes #7828