From 818dd21a4fb1a3f52297537569bfa94eaae18cfb Mon Sep 17 00:00:00 2001 From: Michael Eischer <9106997+MichaelEischer@users.noreply.github.com> Date: Fri, 25 Sep 2026 22:05:12 +0200 Subject: [PATCH] index: hash blob IDs with maphash.Bytes (#22070) Avoid constructing a maphash.Hash on every lookup and insert. --- internal/repository/index/indexmap.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/repository/index/indexmap.go b/internal/repository/index/indexmap.go index d38385aba..f3db6ff5f 100644 --- a/internal/repository/index/indexmap.go +++ b/internal/repository/index/indexmap.go @@ -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()