Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Jan 13, 2026

Prevent closure creation for AssmeblyMetada and ClassMetadata, using GetOrAdd<TArg>(TKey, Func<TKey,TArg,TValue>, TArg)

  • Also removed an extra line

Not a massive saving probably around 100KB on TUnit.TestProject

@thomhurst
Copy link
Owner

Summary

Eliminates closure allocations in metadata caching hot paths by using the state-passing overload of ConcurrentDictionary.GetOrAdd.

Critical Issues

None found ✅

Suggestions

None - this is a clean performance optimization that aligns perfectly with TUnit's "Performance First" principle. The use of static lambdas with the state-passing GetOrAdd overload is exactly the right approach for hot path allocation reduction.

Verdict

APPROVE - No critical issues

Great optimization! This is precisely the kind of hot path improvement that benefits test discovery performance across all TUnit projects.

@thomhurst thomhurst merged commit b6692ca into thomhurst:main Jan 13, 2026
8 of 10 checks passed
This was referenced Jan 14, 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