-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: map's loadFactor is actually 6, not 6.5 #63438
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
Comments
This looks like it was broken in CL 462115. @dr2chase |
Change https://go.dev/cl/533279 mentions this issue: |
The correct load factor is 6.5, not 6. This got broken by accident in CL 462115. Fixes golang#63438 Change-Id: Ib07bb6ab6103aec87cb775bc06bd04362a64e489 Reviewed-on: https://go-review.googlesource.com/c/go/+/533279 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot I believe this should be cherry-pick to 1.21. |
I don't think this qualifies for a backport. It would need to be a serious problem with no workaround. A minor performance difference does not qualify. |
It's not just a minor performance issue, it basically changes the way how a map grows. As the issue mentions, the load factor becomes 6 rather than 6.5 anymore. I already test on 1.20 and 1.22 beta and find that their load factor of map is 6.5 not 6. If we do not cherry-pick this fix to 1.21, only 1.21 becomes an outlier. If any program tracks the memory usage depends on one assumption: the load factor of map in golang is 6.5 not 6. It causes a lot of troubles. |
Sorry, we've made the call that it just isn't worth the risk to backport fixes like this. |
Can I know more details behind the scenes? To me, I could not see any risk, maybe you can help me to understand a little deeper. The load factor number of map in golang is always 6.5, I just could not understand changing back from 6 to 6.5 causses any potential risk. |
It's not anything about the particular CL or how safe it is (although if a CL is particularly risky, we get even more cautious). We just have a policy that we don't backport anything that isn't for a serious problem. |
It's nice to know how the decision was made. Thanks for your time, I really appreciate this. @randall77 |
appreciate the decision to not backport this btw - it seems like it somehow caused a regression (which is quite bizarre) #65706 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I found that due to integer arithmetic , loadFactorNum was incorrectly calculated as 12, resulting map triggers growth when
count > 6*(1<<B)
, instead of the expectedcount > 6.5*(1<<B)
.The code related to the bug I mentioned can be found: code
You can verify this point easily with the following code:
What did you expect to see?
The results of these two benchmark tests should be close.
What did you see instead?
In fact, this first benchmark test only takes half the time each time compared to the second benchmark test. It indicates that map triggers growth, but at this time,
count < 6.5*(1<<B)
still holds true.The text was updated successfully, but these errors were encountered: