Skip to content

Comments

Avoid some redundant list allocations#4963

Open
SimonCropp wants to merge 9 commits intothomhurst:mainfrom
SimonCropp:avoid-some-redundant-list-allocations
Open

Avoid some redundant list allocations#4963
SimonCropp wants to merge 9 commits intothomhurst:mainfrom
SimonCropp:avoid-some-redundant-list-allocations

Conversation

@SimonCropp
Copy link
Contributor

No description provided.

@claude
Copy link
Contributor

claude bot commented Feb 20, 2026

Code Review

Overall this is a clean, well-targeted performance improvement. All 18 files follow the same pattern consistently, every downstream consumer correctly accepts IEnumerable<T>, and no correctness issues were introduced.

Checked for: bugs (including multiple enumeration, deferred execution side effects, thread safety), CLAUDE.md compliance (Performance First, AOT compatibility, dual-mode requirements, snapshot testing rules).


Minor Observation: Double Enumeration in AspireFixture.cs

One removal stands out as slightly counter to the PR's intent. In TUnit.Aspire/AspireFixture.cs, the pending variable is enumerated twice after the .ToList() was removed:

var pending = resourceNames.Where(n => !readySet.Contains(n)); // now lazy

// First enumeration:
logger.LogInformation($"Waiting for {string.Join(", ", pending.Select(n => $"'{n}'"))} ...");

// Second enumeration:
foreach (var name in pending) { ... }

The original .ToList() here was actually intentional — it materializes the filtered set once and re-uses it twice. Without it, the Where predicate runs twice over resourceNames. While this is not a correctness bug (the state doesn't change between the two enumerations, and it's in a timeout/polling code path), it does introduce redundant work rather than eliminating it — the opposite of what the PR aims to do.

A simple fix would be to keep the .ToList() on this specific line, or restructure to iterate pending just once.


All other changes are genuinely beneficial and correct. Nice cleanup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant