Skip to content

perf: replace Min/Max(Range) with Min/MaxIndexBy in DispatchingStrategy#779

Merged
samber merged 1 commit intosamber:masterfrom
d-enk:optimize-dispatching-strategy
Feb 8, 2026
Merged

perf: replace Min/Max(Range) with Min/MaxIndexBy in DispatchingStrategy#779
samber merged 1 commit intosamber:masterfrom
d-enk:optimize-dispatching-strategy

Conversation

@d-enk
Copy link
Contributor

@d-enk d-enk commented Jan 22, 2026

  • Replace Range+MinBy with MinIndexBy in DispatchingStrategyLeast for better performance
  • Replace Range+MaxBy with MaxIndexBy in DispatchingStrategyMost for better performance
  • Use range loop in DispatchingStrategyWeightedRandom for better readability
  • Simplify Buffer function by using local variable in for loop and returning size directly

These changes reduce allocations and improve performance by using more efficient index-finding functions instead of creating intermediate slices with Range().

- Replace Range+MinBy with MinIndexBy in DispatchingStrategyLeast for better performance
- Replace Range+MaxBy with MaxIndexBy in DispatchingStrategyMost for better performance
- Use range loop in DispatchingStrategyWeightedRandom for better readability
- Simplify Buffer function by using local variable in for loop and returning size directly

These changes reduce allocations and improve performance by using more efficient
index-finding functions instead of creating intermediate slices with Range().
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.18%. Comparing base (2859d73) to head (fe10283).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #779      +/-   ##
==========================================
- Coverage   94.18%   94.18%   -0.01%     
==========================================
  Files          18       18              
  Lines        2872     2871       -1     
==========================================
- Hits         2705     2704       -1     
  Misses        151      151              
  Partials       16       16              
Flag Coverage Δ
unittests 94.18% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber samber merged commit d269b33 into samber:master Feb 8, 2026
11 checks passed
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