refactor: reduce allocations for context#816
Conversation
There was a problem hiding this comment.
Pull Request Overview
Refactor to speed up string comparison by avoiding default comparer allocations and leveraging fast, built-in string APIs. Also enables MSTest v4 test parallelization.
- Make comparer parameter nullable across string match types and interface
- Add fast-paths using StringComparison-based APIs when no custom comparer is provided
- Enable assembly-level test parallelization for MSTest4
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Frameworks/aweXpect.Frameworks.MsTest4.Tests/MsTest4FrameworkTests.cs | Adds assembly-level Parallelize attribute to run tests in parallel. |
| Source/aweXpect.Core/Options/StringEqualityOptions.cs | Stops defaulting comparer and passes through nullable comparer; relies on match types to handle null. |
| Source/aweXpect.Core/Options/StringEqualityOptions.WildcardMatchType.cs | Allows nullable comparer in signature. |
| Source/aweXpect.Core/Options/StringEqualityOptions.SuffixMatchType.cs | Adds null-comparer handling with StartsWith/EndsWith fallback using StringComparison. |
| Source/aweXpect.Core/Options/StringEqualityOptions.RegexMatchType.cs | Allows nullable comparer in signature. |
| Source/aweXpect.Core/Options/StringEqualityOptions.PrefixMatchType.cs | Adds null-comparer handling with StartsWith fallback using StringComparison. |
| Source/aweXpect.Core/Options/StringEqualityOptions.ExactMatchType.cs | Adds null-comparer handling with string.Equals fallback using StringComparison. |
| Source/aweXpect.Core/Options/StringEqualityOptions.ContainingMatchType.cs | Adds null-comparer handling with string.Contains fallback; imports System for StringComparison. |
| Source/aweXpect.Core/Core/IStringMatchType.cs | Changes interface contract to accept a nullable comparer. |
Test Results 4 files - 37 4 suites - 37 24s ⏱️ - 3m 29s Results for commit 19c41fd. ± Comparison against base commit bafccdb. This pull request removes 16838 and adds 51 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
🚀 Benchmark ResultsDetails
|
👽 Mutation ResultsaweXpectDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is 81.32%Coverage Thresholds: high:80 low:60 break:0 |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
Source/aweXpect.Core/Core/ResultContexts.cs:66
- The new Add implementation inserts each new node after the head (index 1), changing semantics from append (List.Add) to a modified insertion order. This will reorder contexts compared to previous behavior and may impact message composition. To preserve original append semantics, append to the end of the list: traverse to the tail and set tail._next = context (or maintain a tail pointer for O(1) appends).
public ResultContexts Add(ResultContext context)
{
if (_isOpen)
{
if (_first is null)
{
_first = context;
}
else
{
context._next = _first._next;
_first._next = context;
}
}
return this;
}
|
|
This is addressed in release v2.27.1. |



Refactor to speed up string comparison by avoiding allocations for contexts and default comparer and leveraging fast, built-in string APIs.
Key changes:
ResultContextsand replace with custom implementation