perf: IReadOnlyList<Artifact> call ToArray#4527
Merged
thomhurst merged 1 commit intothomhurst:mainfrom Jan 21, 2026
Merged
Conversation
Owner
SummaryChanges Artifacts property from ToList() to ToArray() to reduce allocations when the collection is empty. Critical IssuesNone found ✅ SuggestionsConsider caching to eliminate repeated allocations: The Artifacts property is accessed multiple times in hot paths (TUnit.Engine/Extensions/TestExtensions.cs:144,146 calls it twice). Each call allocates a new array/list from the ConcurrentBag. While ToArray() is better for empty collections (returns cached Array.Empty), both ToArray() and ToList() allocate for non-empty collections on every access. Consider caching if the bag is immutable after test execution starts. This would eliminate all repeated allocations. Verdict✅ APPROVE - The change improves performance for the common case (empty collections). |
This was referenced Jan 25, 2026
This was referenced Feb 2, 2026
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.
Call
ToArrayinstead ofToList, most of the time the underlying collection contains zero items so it will return an empty array.Before
After