-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Speed up counting of bits in allocator #104968
Conversation
@twpayne: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Welcome @twpayne! |
Hi @twpayne. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @smarterclayton |
/unassign @smarterclayton |
we should have some benchmarks demonstrating this |
The code that this replaces performs the following steps:
The replacement code in this PR performs the following steps:
Is it necessary to demonstrate that the replacement code is faster than the replaced code with a benchmark? |
yep |
Benchmark: goos: linux goarch: amd64 pkg: k8s.io/kubernetes/pkg/registry/core/service/allocator cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz Before: BenchmarkCountBits-8 9459236 140.4 ns/op After: BenchmarkCountBits-8 140667842 9.541 ns/op
OK, benchmark: Before:
After:
|
/assign @smarterclayton |
/ok-to-test |
On 32-bit machines Note that |
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.
Thanks!
/lgtm
/approve
@@ -24,8 +24,8 @@ import ( | |||
// countBits returns the number of set bits in n | |||
func countBits(n *big.Int) int { | |||
var count int = 0 | |||
for _, b := range n.Bytes() { | |||
count += bits.OnesCount8(uint8(b)) | |||
for _, w := range n.Bits() { |
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.
The docs for math/big.Word say "A Word represents a single digit of a multi-precision unsigned integer" which is certainly not explaining very much.
The docs for Bits() say "Bits is intended to support implementation of missing low-level Int functionality outside this package; it should be avoided otherwise." I guess this counts as "missing low-level Int functionality".
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aanm, thockin, twpayne The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/sig network |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR tidies up counting of bits in
pkg/registry/core/service/allocator
.Switching from using
math/big.Int.Bytes
tomath/big.Int.Bits
has two effects:[]byte
).Which issue(s) this PR fixes:
NONE
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: