moq.analyzers icon indicating copy to clipboard operation
moq.analyzers copied to clipboard

Refactor IBenchmarkRegressionStrategy implementations to reduce code duplication through common variability analysis

Open coderabbitai[bot] opened this issue 4 months ago • 5 comments
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:

  • P95RatioRegressionStrategy
  • MeanPercentageRegressionStrategy
  • MeanWallClockRegressionStrategy
  • PercentageRegressionStrategy
  • PercentileRegressionStrategy

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:

  1. Reduce code duplication
  2. Improve maintainability
  3. Ensure consistent behavior across strategies
  4. Make it easier to add new regression detection strategies

Acceptance Criteria

  • [ ] Analyze commonalities across all IBenchmarkRegressionStrategy implementations
  • [ ] 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

coderabbitai[bot] avatar Jul 22 '25 01:07 coderabbitai[bot]