repository: optimize MasterIndex.Each

Sending data through a channel at very high frequency is extremely
inefficient. Thus use simple callbacks instead of channels.

> name                old time/op  new time/op  delta
> MasterIndexEach-16   6.68s ±24%   0.96s ± 2%  -85.64%  (p=0.008 n=5+5)
This commit is contained in:
Michael Eischer
2022-08-19 20:04:39 +02:00
parent 825b95e313
commit 1ebd57247a
14 changed files with 68 additions and 91 deletions

View File

@@ -355,11 +355,11 @@ func TestIndexUnserialize(t *testing.T) {
}
func listPack(idx *repository.Index, id restic.ID) (pbs []restic.PackedBlob) {
for pb := range idx.Each(context.TODO()) {
idx.Each(context.TODO(), func(pb restic.PackedBlob) {
if pb.PackID.Equal(id) {
pbs = append(pbs, pb)
}
}
})
return pbs
}