From fbfb41e6389089b637562b41e05d40f5581b3bbd Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 20 Aug 2019 11:03:13 -0700 Subject: runtime: switch default order of hashing algorithms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the standard hasher is memhash, which checks whether aes instructions are available, and if so redirects to aeshash. With this CL, we call aeshash directly, which then redirects to the fallback hash if aes instructions are not available. This reduces the overhead for the hash function in the common case, as it requires just one call instead of two. On architectures which have no assembly hasher, it's a single jump slower. Thanks to Martin for this idea. name old time/op new time/op delta BigKeyMap-4 22.6ns ± 1% 21.1ns ± 2% -6.55% (p=0.000 n=9+10) Change-Id: Ib7ca77b63d28222eb0189bc3d7130531949d853c Reviewed-on: https://go-review.googlesource.com/c/go/+/190998 Reviewed-by: Martin Möhrmann --- src/runtime/alg.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/runtime/alg.go') diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 732d32bf41..57306f81d9 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -88,14 +88,14 @@ var algarray = [alg_max]typeAlg{ var useAeshash bool // in asm_*.s -func aeshash(p unsafe.Pointer, h, s uintptr) uintptr -func aeshash32(p unsafe.Pointer, h uintptr) uintptr -func aeshash64(p unsafe.Pointer, h uintptr) uintptr -func aeshashstr(p unsafe.Pointer, h uintptr) uintptr +func memhash(p unsafe.Pointer, h, s uintptr) uintptr +func memhash32(p unsafe.Pointer, h uintptr) uintptr +func memhash64(p unsafe.Pointer, h uintptr) uintptr +func strhash(p unsafe.Pointer, h uintptr) uintptr -func strhash(a unsafe.Pointer, h uintptr) uintptr { +func strhashFallback(a unsafe.Pointer, h uintptr) uintptr { x := (*stringStruct)(a) - return memhash(x.str, h, uintptr(x.len)) + return memhashFallback(x.str, h, uintptr(x.len)) } // NOTE: Because NaN != NaN, a map can contain any @@ -305,14 +305,7 @@ func alginit() { } func initAlgAES() { - if GOOS == "aix" { - // runtime.algarray is immutable on AIX: see cmd/link/internal/ld/xcoff.go - return - } useAeshash = true - algarray[alg_MEM32].hash = aeshash32 - algarray[alg_MEM64].hash = aeshash64 - algarray[alg_STRING].hash = aeshashstr // Initialize with random data so hash collisions will be hard to engineer. getRandomData(aeskeysched[:]) } -- cgit v1.3-6-g1900