-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: map iteration not random in Go 1.3 #8410
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
Labels
Milestone
Comments
The patch changeset: 18847:6ea672cbfe43 user: Josh Bleecher Snyder <josharian@gmail.com> date: Tue Jan 14 12:54:05 2014 -0800 summary: runtime: change map iteration randomization to use intra-bucket offset changed randomization to cyclically shuffle each bucket, but doesn't start iteration at a random bucket. As a consequence When a map is very sparse (1 item per bucket), randomization is ineffective. Another issue is that a "pop" pattern: deleting an element of the map after first iteration, will leave the map in a very unbalanced state. Popping all elements will take a quadratic time instead of something like O(n log n) or maybe a bit more as it is in Go 1.2. |
We're not shooting for perfect iteration randomness. We only provide enough randomness to make sure people aren't depending on iteration order. We do it to ensure that we can change the map implementation at some future time and not break people's incorrect code. Yes, the iteration is not random if the first bucket has <=1 element. That will only happen with very sparse maps, which requires inserting and then deleting most elements. I'm not particularly worried about that corner case. The O(n^2) pop problem is more worrying. Starting at a random bucket as in 1.2 would help. Maybe better is to keep track of (a conservative approximation of) the minimum nonempty bucket. |
I've split out the O(n^2) performance problem into issue #8412. Let's keep this bug about the nonrandomness. |
CL https://golang.org/cl/137560044 mentions this issue. |
This issue was closed by revision d6cd230. Status changed to Fixed. |
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jun 25, 2018
The behavior was fixed in CL 141270043. Add a test. Fixes golang#8410. LGTM=khr R=khr, remyoudompheng CC=golang-codereviews https://golang.org/cl/137560044
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jul 9, 2018
The behavior was fixed in CL 141270043. Add a test. Fixes golang#8410. LGTM=khr R=khr, remyoudompheng CC=golang-codereviews https://golang.org/cl/137560044
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jul 30, 2018
The behavior was fixed in CL 141270043. Add a test. Fixes golang#8410. LGTM=khr R=khr, remyoudompheng CC=golang-codereviews https://golang.org/cl/137560044
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Attachments:
The text was updated successfully, but these errors were encountered: