aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map_fast32.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2020-05-03 16:26:05 +0200
committerMartin Möhrmann <moehrmann@google.com>2020-08-17 04:56:56 +0000
commitf979d072d339a24e4938d46588c153587d61af19 (patch)
treea846d2e135e54d7ab3d4e59ed948a17f72a008e2 /src/runtime/map_fast32.go
parent99f179f55a66f35dc7861fa411b42ed61bd0df31 (diff)
downloadgo-f979d072d339a24e4938d46588c153587d61af19.tar.gz
go-f979d072d339a24e4938d46588c153587d61af19.zip
runtime: avoid memclr call for keys in mapdelete_fast
Replace memclrHasPointers calls for keys in mapdelete_fast* functions with direct writes since the key sizes are known at compile time. name old time/op new time/op delta MapDelete/Pointer/100 33.7ns ± 1% 23.7ns ± 2% -29.68% (p=0.000 n=7+9) MapDelete/Pointer/1000 41.6ns ± 5% 34.9ns ± 4% -16.01% (p=0.000 n=9+10) MapDelete/Pointer/10000 45.6ns ± 1% 38.2ns ± 2% -16.34% (p=0.000 n=8+10) Change-Id: Icaac43b520b93c2cf9fd192b822fae7203a7bbf7 Reviewed-on: https://go-review.googlesource.com/c/go/+/231737 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/map_fast32.go')
-rw-r--r--src/runtime/map_fast32.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/runtime/map_fast32.go b/src/runtime/map_fast32.go
index 534454f3ad..d035ed0386 100644
--- a/src/runtime/map_fast32.go
+++ b/src/runtime/map_fast32.go
@@ -299,8 +299,12 @@ search:
continue
}
// Only clear key if there are pointers in it.
- if t.key.ptrdata != 0 {
- memclrHasPointers(k, t.key.size)
+ // This can only happen if pointers are 32 bit
+ // wide as 64 bit pointers do not fit into a 32 bit key.
+ if sys.PtrSize == 4 && t.key.ptrdata != 0 {
+ // The key must be a pointer as we checked pointers are
+ // 32 bits wide and the key is 32 bits wide also.
+ *(*unsafe.Pointer)(k) = nil
}
e := add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.elemsize))
if t.elem.ptrdata != 0 {