Skip to content

Commit d1f627f

Browse files
committed
doc/go1.3.html: add note about small map iteration order
LGTM=r R=r CC=golang-codereviews https://golang.org/cl/98290048
1 parent 23e8c0d commit d1f627f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/go1.3.html

+22
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ <h3 id="garbage_collector">Changes to the garbage collector</h3>
137137
Such code can be identified by <code>go vet</code>.
138138
</p>
139139

140+
<h3 id="map">Map iteration</h3>
141+
142+
<p>
143+
Iterations over small maps no longer happen in a consistent order.
144+
Go 1 defines that &ldquo;<a href="http://golang.org/ref/spec#For_statements">The iteration order over maps
145+
is not specified and is not guaranteed to be the same from one iteration to the next.</a>&rdquo;
146+
To keep code from depending on map iteration order,
147+
Go 1.0 started each map iteration at a random index in the map.
148+
A new map implementation introduced in Go 1.1 neglected to randomize
149+
iteration for maps with eight or fewer entries, although the iteration order
150+
can still vary from system to system.
151+
This has allowed people to write Go 1.1 and Go 1.2 programs that
152+
depend on small map iteration order and therefore only work reliably on certain systems.
153+
Go 1.3 reintroduces random iteration for small maps in order to flush out these bugs.
154+
</p>
155+
156+
<p>
157+
<em>Updating</em>: If code assumes a fixed iteration order for small maps,
158+
it will break and must be rewritten not to make that assumption.
159+
Because only small maps are affected, the problem arises most often in tests.
160+
</p>
161+
140162
<h3 id="liblink">The linker</h3>
141163

142164
<p>

0 commit comments

Comments
 (0)