Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

Small improvement, saves around 2 MB in ScopedAttributeFilter.FilterScopedAttributes by deferring Dictionary creation and using ValueListBuilder

Before

image

After

image

@thomhurst
Copy link
Owner

Summary

Performance optimization that uses ValueListBuilder and defers Dictionary allocation in ScopedAttributeFilter, saving ~2 MB.

Critical Issues

None found ✅

The changes look good:

  • Proper use of ValueListBuilder with stack allocation
  • Dictionary deferred until scoped attributes are actually encountered
  • Return type change from List to T[] is safe (internal API, all callers just enumerate)
  • Dispose() correctly called on ValueListBuilder
  • Aligns with Rule 4 (Performance First) - minimizes allocations in hot path

Suggestions

Minor: Stack allocation size
The initial stack buffer is [null,null,null,null] (4 elements). Consider using stackalloc T[8] instead for a more typical initial capacity that matches common scenarios, though 4 is fine if profiling shows it's sufficient.

Note: OrderBy allocation
One call site (EventReceiverOrchestrator.cs:244) uses .OrderBy() which allocates anyway. This isn't a blocker, but if optimizing that path later, consider sorting the array in-place or using ValueListBuilder's ability to insert in sorted order.

Verdict

APPROVE - Solid performance improvement with no critical issues

@thomhurst thomhurst merged commit 7240a92 into thomhurst:main Jan 11, 2026
8 of 10 checks passed
This was referenced Jan 12, 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