perf: use sequential processing for small test sets#4299
Conversation
For small test sets (< 8 items), the overhead of parallel processing (task scheduling, thread pool allocation, synchronization) exceeds the parallelization benefits. This change adds a threshold-based optimization that uses sequential processing when the item count is below the threshold, while maintaining parallel processing for larger test sets. Benchmarks (DataDrivenTests with 18 tests): - Before: TUnit ~596ms, MSTest ~546ms (TUnit ~9% slower) - After: TUnit ~540ms, MSTest ~553ms (TUnit ~2% faster) - Improvement: ~56ms (~9.4%) Changes: - Add ParallelThresholds class with MinItemsForParallel = 8 - Modify BuildTestsFromMetadataAsync to check count before processing - Modify AotTestDataCollector to use sequential for small source sets - Use sequential processing for dynamic tests (typically rare) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds threshold-based optimization to use sequential processing for small test sets (< 8 items) to avoid task scheduling overhead. Critical Issues1. DUAL-MODE VIOLATION ❌BLOCKING: This change violates TUnit's critical rule #1 - changes to core engine metadata collection MUST work in both source-gen AND reflection modes. Problem: The optimization is only implemented in Required fix: Apply the same sequential processing logic to 2. Performance: Unnecessary Allocation in Hot Path
|
Summary
Benchmarks
DataDrivenTests (18 tests):
TUnit was ~9% slower than MSTest, now it's ~2% faster.
ScaleTests (150 tests):
Changes
ParallelThresholdsclass withMinItemsForParallel = 8constantBuildTestsFromMetadataAsyncto check count before parallel processingAotTestDataCollector.CollectTestsAsyncto use sequential for small source setsTest plan
🤖 Generated with Claude Code