From 7015ed891c6f4e51ebaa642fce42ea8a1592b4e1 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 1 Sep 2023 18:26:49 +0000 Subject: sync: prevent (*Map).Range from always escaping After the change from CL 426074 the Range method on Map always escape the read variable, leading to an allocation. Since the compiler doesn't do live-range splitting for local variables we need to use some hints to only escape in that particular branch. Fixes #62404 Change-Id: I938a5e593647455fa827e3dd3ed8ea22c7365df1 GitHub-Last-Rev: fcbedb467c7b4e6f1d49e299d243cad70deb34e9 GitHub-Pull-Request: golang/go#62408 Reviewed-on: https://go-review.googlesource.com/c/go/+/524976 Auto-Submit: Bryan Mills LUCI-TryBot-Result: Go LUCI Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/sync/map.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/sync/map.go') diff --git a/src/sync/map.go b/src/sync/map.go index e8ccf58b56..00b2446153 100644 --- a/src/sync/map.go +++ b/src/sync/map.go @@ -461,7 +461,8 @@ func (m *Map) Range(f func(key, value any) bool) { read = m.loadReadOnly() if read.amended { read = readOnly{m: m.dirty} - m.read.Store(&read) + copyRead := read + m.read.Store(©Read) m.dirty = nil m.misses = 0 } -- cgit v1.3