From 3f972df4a7f4be5db219ebd22625594711b68255 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 19 Aug 2017 10:45:38 -0700 Subject: [PATCH] runtime: don't clear pointer-free memory when growing maps MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If there are no pointers, then clearing memory doesn't help GC, and the memory is otherwise dead, so don't bother clearing it. Change-Id: I953f4a3264939f2825e82292030eda2e835cbb97 Reviewed-on: https://go-review.googlesource.com/57350 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Martin Möhrmann --- src/runtime/hashmap.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 17a69646ca..efb8a78024 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -1124,17 +1124,13 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { } } // Unlink the overflow buckets & clear key/value to help GC. - if h.flags&oldIterator == 0 { - b = (*bmap)(add(h.oldbuckets, oldbucket*uintptr(t.bucketsize))) + if h.flags&oldIterator == 0 && t.bucket.kind&kindNoPointers == 0 { + b := add(h.oldbuckets, oldbucket*uintptr(t.bucketsize)) // Preserve b.tophash because the evacuation // state is maintained there. - ptr := add(unsafe.Pointer(b), dataOffset) + ptr := add(b, dataOffset) n := uintptr(t.bucketsize) - dataOffset - if t.bucket.kind&kindNoPointers == 0 { - memclrHasPointers(ptr, n) - } else { - memclrNoHeapPointers(ptr, n) - } + memclrHasPointers(ptr, n) } } -- 2.50.0