]> Cypherpunks repositories - gostls13.git/commit
runtime: change map iteration randomization to use intra-bucket offset
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 14 Jan 2014 20:54:05 +0000 (12:54 -0800)
committerKeith Randall <khr@golang.org>
Tue, 14 Jan 2014 20:54:05 +0000 (12:54 -0800)
commit3be4d95731a17073afb1f69bde264eecbdfa32bb
tree698f9f1d8074ffb389d123da44ae1e97935b281b
parent1e2b13355f888be3f9d31624ad178c4e4b0bb3f6
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 #6719.

R=khr, bradfitz
CC=golang-codereviews
https://golang.org/cl/47370043
src/cmd/gc/reflect.c
src/pkg/runtime/hashmap.c
src/pkg/runtime/map_test.go