perf: optimize GetEligibleEventObjects with single-allocation approach#4307
perf: optimize GetEligibleEventObjects with single-allocation approach#4307
Conversation
SummaryPerformance optimization that eliminates triple allocation in Critical IssuesNone found ✅ AnalysisThis PR implements solid performance optimizations in hot-path code (test discovery/execution): TestContextExtensions.cs
EventReceiverOrchestrator.cs
HookExecutor.cs
Performance characteristicsAll changes follow TUnit's "Performance First" principle (CLAUDE.md rule #4):
Code quality
Verdict✅ APPROVE - Well-executed performance optimization with no critical issues |
Replaces the previous implementation that used: - List allocation + ToArray() + OfType<object>().ToArray() - Three separate allocations for the same data New implementation: - Counts non-null items first to determine exact array size - Single array allocation with exact size needed - Direct population without intermediate collections - Eliminates LINQ overhead from OfType<object>() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4187b28 to
6fb1790
Compare
SummaryEliminates triple allocation in hot-path event object collection by counting non-nulls first, then allocating a single exact-sized array. Critical IssuesNone found ✅ AnalysisThis PR optimizes Allocation Reduction
Code Quality
TUnit Rule Compliance
Minor ObservationThe manual loop approach in counting helpers is correct for avoiding LINQ overhead, consistent with TUnit's performance-first principle. Previous Review StatusAuthor (thomhurst) already approved with same findings. Verdict✅ APPROVE - Clean performance optimization with no critical issues |
Summary
GetEligibleEventObjects(List + ToArray + OfType.ToArray)OfType<object>()Previous implementation
New implementation
Test plan
🤖 Generated with Claude Code