Skip to content

perf: reduce TreeNodeFilter allocations via IReadOnlyList and ReadOnlySpan#8238

Open
abdelghani-moussaid wants to merge 3 commits into
microsoft:mainfrom
abdelghani-moussaid:optimize-tree-node-filter
Open

perf: reduce TreeNodeFilter allocations via IReadOnlyList and ReadOnlySpan#8238
abdelghani-moussaid wants to merge 3 commits into
microsoft:mainfrom
abdelghani-moussaid:optimize-tree-node-filter

Conversation

@abdelghani-moussaid
Copy link
Copy Markdown

@abdelghani-moussaid abdelghani-moussaid commented May 14, 2026

Performance optimization for TreeNodeFilter to eliminate allocations during test discovery.

Key Changes:

  • Widened SubExpressions to IReadOnlyList to avoid IEnumerator boxing.
  • Implemented ReadOnlySpan-based recursion for .NET 8.0+ to eliminate O(N) string fragment allocations.
  • Refactored Span path to use foreach loops to satisfy the CS9108 ref-struct capture constraint.

Verification Results:

  • BenchmarkDotNet: 160 B -> 0 B allocations on .NET 8.0. Execution time reduced by ~45%.

Unit Tests: All local TreeNodeFilter tests passed.


Related

…ySpan

- Widen SubExpressions to IReadOnlyList to enable optimized LINQ paths.
- Implement ReadOnlySpan-based matching for .NET 8.0+ to eliminate
  string fragment allocations.
- Use procedural loops in Span path to avoid ref-struct capture (CS9108).
Copilot AI review requested due to automatic review settings May 14, 2026 21:36
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