-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
internal/grpcrand: use Go top-level random functions for go1.21+ #6925
Conversation
88e8787
to
d09ffd6
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #6925 +/- ##
==========================================
+ Coverage 83.51% 83.76% +0.25%
==========================================
Files 287 287
Lines 30920 30911 -9
==========================================
+ Hits 25824 25894 +70
+ Misses 4020 3957 -63
+ Partials 1076 1060 -16
|
d09ffd6
to
4c3353e
Compare
@dfawley, I would appreciate if you could take a look at this. |
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.
LGTM. Thanks @kmirzavaziri
internal/grpcrand/grpcrand.go
Outdated
@@ -1,3 +1,6 @@ | |||
//go:build !go1.21 | |||
// +build !go1.21 |
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.
Would you mind adding a TODO here that says something like:
"TODO: when this file is deleted (after Go 1.20 support is dropped), delete all of grpcrand and call the rand package directly."
?
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.
Done
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.
Sorry for my absence and thank you @arvindbr8
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.
No worries, sorry if you were working on the branch. Since this was a oneliner change, and since you had also allowed edits to your PR by maintainers I went ahead and made the change.
internal/grpcrand/grpcrand.go
Outdated
@@ -1,3 +1,6 @@ | |||
//go:build !go1.21 | |||
// +build !go1.21 |
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.
We don't need both syntaxes for this, since we don't support Go 1.16 or earlier. Just //go:build
is fine.
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.
Done
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.
ty @arvindbr8
This PR closes issue #6650.
What I did
I duplicated all functions in
grpcrand
package into another file, changing the implementation to call top-level functions of Gomath/rand
package internally, adding the_go1.21
suffix to new file name and build comments to both files, to instruct the Go compiler to compile the new file instead of the original one for Go 1.21 or higher.Why
As described in the related issue, apart from reducing complexity, it is concurrent safe as of Go 1.21, and also significantly faster. I ran a benchmark to demonstrate the difference.
results:
Making the functions ~5x faster.
RELEASE NOTES:
grpcrand
by adoptingmath/rand
's top-level functions for go version 1.21.0 and newer.