Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

Removes string[] and WhereArrayIterator allocations by using ValueStringBuilder

Allocations that are eliminated

image image

@thomhurst
Copy link
Owner

Summary

Eliminates array and LINQ allocations in test output methods by using stack-based ValueStringBuilder.

Critical Issues

  1. Missing static modifier (TestContext.Output.cs:107): The AppendIfNotNullOrEmpty method should be declared as static since it doesn't access instance state:
    static void AppendIfNotNullOrEmpty(ref ValueStringBuilder builder, string? value)

Suggestions

None - the performance optimization is well-targeted and the ValueStringBuilder implementation from dotnet/runtime is battle-tested.

TUnit Rules Compliance

Performance First - Directly addresses this rule by eliminating hot-path allocations
AOT Compatible - Ref struct with no reflection concerns
Modern C# - Uses modern span-based APIs

Verdict

⚠️ REQUEST CHANGES - One minor but required fix (missing static modifier)

@TimothyMakkison
Copy link
Contributor Author

Missing static modifier

Fixed 👍

Hopefully this PR proves that I messed up the logic on #4231. I'll give it another try if this PR passes the CI

@thomhurst thomhurst merged commit 76f072c into thomhurst:main Jan 9, 2026
7 of 10 checks passed
This was referenced Jan 9, 2026
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.

2 participants