]> Cypherpunks repositories - gostls13.git/commit
internal/runtime/maps: hash copy of key instead of key itself
authorKeith Randall <khr@golang.org>
Tue, 19 Nov 2024 00:37:59 +0000 (16:37 -0800)
committerKeith Randall <khr@golang.org>
Tue, 19 Nov 2024 21:15:55 +0000 (21:15 +0000)
commitd13e6d0b089b72d666d0dd46f4965660ab10b712
tree873f92d46c50520a43d3d441c721c639dd533f5e
parentc14fc500c772c35050699f3bcc3688db3d0fbed2
internal/runtime/maps: hash copy of key instead of key itself

Hashing the key means we have to take the address of it. That inhibits
subsequent optimizations on the key variable.

By hashing a copy, we incur an extra store at the hash callsite, but
we no longer need a load of the key in the inner loop. It can live
in a register throughout. (Technically, it gets spilled around
the call to the hasher, but it gets restored outside the loop.)

Maybe one day we can have special hash functions that take
int64/int32/string instead of *int64/*int32/*string.

Change-Id: Iba3133f6e82328f53c0abcb5eec13ee47c4969d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/629419
Reviewed-by: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/internal/runtime/maps/runtime_fast32_swiss.go
src/internal/runtime/maps/runtime_fast64_swiss.go
src/internal/runtime/maps/runtime_faststr_swiss.go