diff options
author | Keith Randall <khr@golang.org> | 2020-02-13 08:34:41 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2020-02-24 19:41:31 +0000 |
commit | afd691c579198387c874512ef1c75db651dba9bd (patch) | |
tree | 39b2fd8f5ad02b9431d3afa8edbeb28c77d36bc6 /src/runtime/alg.go | |
parent | 1c0d664128ed5f1d7c66afb69cb2d15064a1ba43 (diff) | |
download | go-afd691c579198387c874512ef1c75db651dba9bd.tar.gz go-afd691c579198387c874512ef1c75db651dba9bd.zip |
runtime: special case interface hashing for pointers
Interfaces often contain pointers. Implement a fast path for this case.
name old time/op new time/op delta
MapInterfaceString-16 21.4ns ±19% 20.5ns ±10% ~ (p=0.361 n=10+10)
MapInterfacePtr-16 25.8ns ± 8% 17.3ns ± 7% -33.11% (p=0.000 n=10+9)
Fixes #37086
Change-Id: Ice52820e6259a3edeafcbbbeb25b1e363bef00d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/219338
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/alg.go')
-rw-r--r-- | src/runtime/alg.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index d8789b4b5f..5a0656513d 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -160,7 +160,15 @@ func nilinterhash(p unsafe.Pointer, h uintptr) uintptr { // maps generated by reflect.MapOf (reflect_typehash, below). func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr { if t.tflag&tflagRegularMemory != 0 { - return memhash(p, h, t.size) + // Handle ptr sizes specially, see issue 37086. + switch t.size { + case 4: + return memhash32(p, h) + case 8: + return memhash64(p, h) + default: + return memhash(p, h, t.size) + } } switch t.kind & kindMask { case kindFloat32: |