-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: transition to math/rand/v2
for Improved Performance and Code Clarity
#15438
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15438 +/- ##
==========================================
+ Coverage 65.63% 65.65% +0.01%
==========================================
Files 1562 1563 +1
Lines 194249 194379 +130
==========================================
+ Hits 127502 127618 +116
- Misses 66747 66761 +14 ☔ View full report in Codecov by Sentry. |
I don't think we should keep using this hack, but switch to https://pkg.go.dev/math/rand/v2#Uint32N from the only place where we use this, namely in |
Should go/hack be cleaned up? |
Yes, we can then clean up |
You'll also need to fix the DCO check. |
Signed-off-by: Aoang <[email protected]>
6497d4d
to
1e0aa22
Compare
@Aoang Can you update the PR description as well with how the new approach works? |
runtime.fastrand
to use cheaprand
for compatibility with Go 1.22math/rand/v2
for Improved Performance and Code Clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmg Wanna also take a look here?
Description
This Pull Request removes a reference to runtime.fastrand in
go/hack/runtime.go
and replaces a call tohack.FastRand()
withmath/rand/v2.Uint32N
ingo/pools/smartconnpool/pool.go
. These change aim to enhance code readability, performance, and reduce dependency on specific runtime implementations.math/rand/v2
employs Lemire's algorithm in functions such as N, IntN, UintN, and others. Preliminary benchmark tests show a 40% improvement compared toInt31n
inv1
and a 75% improvement compared toInt63n
inv1
.Furthermore,
math/rand/v2
default utilizes ChaCha8 for the global random number generator in each OS thread.Related Issue(s)
Checklist
Deployment Notes