moq.analyzers
moq.analyzers copied to clipboard
Refactor IBenchmarkRegressionStrategy implementations to reduce code duplication through common variability analysis
trafficstars
Problem
The qltysh static analysis tool has identified significant code duplication in the IBenchmarkRegressionStrategy implementations, with 88 lines of similar code across 2 locations (mass = 612).
Background
As part of PR #565, multiple regression detection strategies were introduced:
P95RatioRegressionStrategyMeanPercentageRegressionStrategyMeanWallClockRegressionStrategyPercentageRegressionStrategyPercentileRegressionStrategy
These implementations share conceptual similarities in their approach to:
- Filtering regression results into 'better' and 'worse' categories
- Applying thresholds (both relative and absolute)
- Logging detailed performance information
- Computing geometric means
- Excluding infinite ratios
Proposed Solution
Apply common variability analysis to identify invariant concepts that can be elevated into a shared abstraction. This would:
- Reduce code duplication
- Improve maintainability
- Ensure consistent behavior across strategies
- Make it easier to add new regression detection strategies
Acceptance Criteria
- [ ] Analyze commonalities across all
IBenchmarkRegressionStrategyimplementations - [ ] Design and implement a base class or helper that captures invariant behavior
- [ ] Refactor existing strategies to use the common abstraction
- [ ] Ensure no regression in functionality
- [ ] Update tests to cover the refactored implementation
References
- Original PR: https://github.com/rjmurillo/moq.analyzers/pull/565
- Discussion: https://github.com/rjmurillo/moq.analyzers/pull/565#discussion_r2217992922
- Static analysis finding: https://qlty.sh/gh/rjmurillo/projects/moq.analyzers/issues/qlty/similar-code/issues/850d82b419fc55e5568f994a2ca69514