Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(937)

Issue 47370043: code review 47370043: runtime: make map iteration start at a random offset wi... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 6 months ago by josharian
Modified:
11 years, 5 months ago
Reviewers:
khr
CC:
khr, bradfitz, golang-codereviews
Visibility:
Public.

Description

runtime: change map iteration randomization to use intra-bucket offset Map iteration previously started from a random bucket, but walked each bucket from the beginning. Now, iteration always starts from the first bucket and walks each bucket starting at a random offset. For performance, the random offset is selected at the start of iteration and reused for each bucket. Iteration over a map with 8 or fewer elements--a single bucket--will now be non-deterministic. There will now be only 8 different possible map iterations. Significant benchmark changes, on my OS X laptop (rough but consistent): benchmark old ns/op new ns/op delta BenchmarkMapIter 128 121 -5.47% BenchmarkMapIterEmpty 4.26 4.45 +4.46% BenchmarkNewEmptyMap 114 111 -2.63% Fixes issue 6719.

Patch Set 1 #

Patch Set 2 : code review 47370043: runtime: make map iteration start at a random offset wi... #

Patch Set 3 : diff -r 1c86edd196bd https://code.google.com/p/go #

Total comments: 2

Patch Set 4 : diff -r 9d0f388bbe40 https://code.google.com/p/go #

Patch Set 5 : diff -r 9d0f388bbe40 https://code.google.com/p/go #

Patch Set 6 : diff -r 270e6a19b4ec https://code.google.com/p/go #

Patch Set 7 : diff -r 270e6a19b4ec https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+25 lines, -25 lines) Patch
M src/cmd/gc/reflect.c View 1 2 3 4 5 6 3 chunks +5 lines, -5 lines 0 comments Download
M src/pkg/runtime/hashmap.c View 1 2 3 4 5 8 chunks +19 lines, -18 lines 0 comments Download
M src/pkg/runtime/map_test.go View 1 2 1 chunk +1 line, -2 lines 0 comments Download

Messages

Total messages: 7
khr
https://codereview.appspot.com/47370043/diff/40001/src/pkg/runtime/hashmap.c File src/pkg/runtime/hashmap.c (right): https://codereview.appspot.com/47370043/diff/40001/src/pkg/runtime/hashmap.c#newcode787 src/pkg/runtime/hashmap.c:787: it->bucket = it->endbucket = (rand >> BUCKETSIZE_BITS) & (((uintptr)1 ...
11 years, 6 months ago (2014-01-06 06:11:28 UTC) #1
josharian
Hello khr@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
11 years, 6 months ago (2014-01-06 13:30:26 UTC) #2
josharian
https://codereview.appspot.com/47370043/diff/40001/src/pkg/runtime/hashmap.c File src/pkg/runtime/hashmap.c (right): https://codereview.appspot.com/47370043/diff/40001/src/pkg/runtime/hashmap.c#newcode787 src/pkg/runtime/hashmap.c:787: it->bucket = it->endbucket = (rand >> BUCKETSIZE_BITS) & (((uintptr)1 ...
11 years, 6 months ago (2014-01-06 13:30:50 UTC) #3
josharian
PTAL New: * No longer randomize starting bucket (cf discussion in CL 48340043 and CL ...
11 years, 5 months ago (2014-01-13 02:53:57 UTC) #4
khr
On 2014/01/13 02:53:57, josharian wrote: > PTAL > > New: > > * No longer ...
11 years, 5 months ago (2014-01-14 05:00:12 UTC) #5
bradfitz
Keith, You want to submit this for Josh? On Mon, Jan 13, 2014 at 9:00 ...
11 years, 5 months ago (2014-01-14 17:39:57 UTC) #6
khr
11 years, 5 months ago (2014-01-14 20:54:08 UTC) #7
*** Submitted as https://code.google.com/p/go/source/detail?r=6ea672cbfe43 ***

runtime: change map iteration randomization to use intra-bucket offset

Map iteration previously started from a random bucket, but walked each
bucket from the beginning. Now, iteration always starts from the first
bucket and walks each bucket starting at a random offset. For
performance, the random offset is selected at the start of iteration
and reused for each bucket.

Iteration over a map with 8 or fewer elements--a single bucket--will
now be non-deterministic. There will now be only 8 different possible
map iterations.

Significant benchmark changes, on my OS X laptop (rough but consistent):

benchmark                              old ns/op     new ns/op     delta
BenchmarkMapIter                       128           121           -5.47%
BenchmarkMapIterEmpty                  4.26          4.45          +4.46%
BenchmarkNewEmptyMap                   114           111           -2.63%

Fixes issue 6719.

R=khr, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/47370043

Committer: Keith Randall <khr@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b