Skip to content

Commit

Permalink
internal/runtime/maps: linear scan of small map
Browse files Browse the repository at this point in the history
We still use the hash and control word, but loop over all 8 bytes
instead of doing the match operation, which ends up being slightly
faster when there is only one group.

Note that specialized variants added later will avoid hashing at all.

For golang#54766.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap
Change-Id: I3bb353b023dd6120b6585e87d3efe2f18ac9e1ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/611189
Reviewed-by: Keith Randall <[email protected]>
Auto-Submit: Michael Pratt <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
prattmic authored and gopherbot committed Oct 28, 2024
1 parent 77e3d8c commit 808da68
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/internal/runtime/maps/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,20 @@ func (m *Map) getWithKeySmall(hash uintptr, key unsafe.Pointer) (unsafe.Pointer,
data: m.dirPtr,
}

match := g.ctrls().matchH2(h2(hash))
h2 := uint8(h2(hash))
ctrls := *g.ctrls()

for match != 0 {
i := match.first()
for i := uint32(0); i < abi.SwissMapGroupSlots; i++ {
c := uint8(ctrls)
ctrls >>= 8
if c != h2 {
continue
}

slotKey := g.key(i)
if m.typ.Key.Equal(key, slotKey) {
return slotKey, g.elem(i), true
}
match = match.removeFirst()
}

return nil, nil, false
Expand Down

0 comments on commit 808da68

Please sign in to comment.