Michael Jones notes that the following pattern is common in Go code:
if v, ok := map[key]; ok { // or !ok
....
map[key] = newValue
}
If hashing that key type is expensive (say: large string/struct) and the map isn't empty
or very small, the above code does it twice.
If we kept a per-P cache of the last key & last computed hash value for that P, we
could eliminate some hash calls.
Probably worth measuring. (Probably not for Go 1.1)
Michael Jones notes that the following pattern is common in Go code: if v, ok := map[key]; ok { // or !ok .... map[key] = newValue } If hashing that key type is expensive (say: large string/struct) and the map isn't empty or very small, the above code does it twice. If we kept a per-P cache of the last key & last computed hash value for that P, we could eliminate some hash calls. Probably worth measuring. (Probably not for Go 1.1)