-
Notifications
You must be signed in to change notification settings - Fork 291
Fix O(n²) per-node UID lookup in TestNodeUidListFilter re-run path #7806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using Microsoft.Testing.Platform.Requests; | ||
|
|
||
| using PlatformTestNodeUid = Microsoft.Testing.Platform.Extensions.Messages.TestNodeUid; | ||
|
|
||
| namespace Microsoft.Testing.Framework; | ||
|
|
||
| internal sealed class BFSTestNodeVisitor | ||
|
|
@@ -32,6 +34,11 @@ public BFSTestNodeVisitor(IEnumerable<TestNode> rootTestNodes, ITestExecutionFil | |
|
|
||
| public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNodeAsync) | ||
| { | ||
| // Precompute a HashSet for O(1) UID lookups when filtering by UID list. | ||
| HashSet<PlatformTestNodeUid>? uidFilterSet = _testExecutionFilter is TestNodeUidListFilter listFilter | ||
| ? [.. listFilter.TestNodeUids] | ||
| : null; | ||
|
|
||
| // This is case sensitive, and culture insensitive, to keep UIDs unique, and comparable between different system. | ||
| Dictionary<TestNodeUid, List<TestNode>> testNodesByUid = []; | ||
| Queue<(TestNode CurrentNode, TestNodeUid? ParentNodeUid, StringBuilder NodeFullPath)> queue = new(); | ||
|
|
@@ -81,8 +88,8 @@ public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNo | |
| } | ||
|
|
||
| // If the node is not filtered out by the test execution filter, we call the callback with the node. | ||
| if (_testExecutionFilter is not TestNodeUidListFilter listFilter | ||
| || listFilter.TestNodeUids.Any(uid => currentNode.StableUid.ToPlatformTestNodeUid() == uid)) | ||
| if (uidFilterSet is null | ||
| || uidFilterSet.Contains(currentNode.StableUid.ToPlatformTestNodeUid())) | ||
|
Comment on lines
+91
to
+92
|
||
| { | ||
| await onIncludedTestNodeAsync(currentNode, parentNodeUid).ConfigureAwait(false); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this sample,
uidFilterSetis aHashSet<TestNodeUid>butContainsis called with an interpolatedstring, which relies on the implicitstring -> TestNodeUidconversion and allocates a newTestNodeUidper check. If you want this to be allocation-free, consider storinguid.Valuein aHashSet<string>(e.g., withStringComparer.Ordinal) and comparing against the computed UID string.