index: hash blob IDs with maphash.Bytes (#22070)

Avoid constructing a maphash.Hash on every lookup and insert.
This commit is contained in:
Michael Eischer
2026-09-25 22:05:12 +02:00
committed by GitHub
parent 6adedec6b4
commit 818dd21a4f
+3 -5
View File
@@ -31,7 +31,7 @@ type indexMap struct {
buckets []uint
numentries uint
mh maphash.Hash
seed maphash.Seed
blockList hashedArrayTree
}
@@ -176,15 +176,13 @@ func (m *indexMap) hash(id restic.ID) uint {
// While SHA-256 should be collision-resistant, for hash table indices
// we use only a few bits of it and finding collisions for those is
// much easier than breaking the whole algorithm.
mh := maphash.Hash{}
mh.SetSeed(m.mh.Seed())
_, _ = mh.Write(id[:])
h := uint(mh.Sum64())
h := uint(maphash.Bytes(m.seed, id[:]))
return h & uint(len(m.buckets)-1)
}
func (m *indexMap) init() {
const initialBuckets = 64
m.seed = maphash.MakeSeed()
m.buckets = make([]uint, initialBuckets)
// first entry in blockList serves as null byte
m.blockList = *newHAT()