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

@@ -595,10 +595,15 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
// sanity check
ctx, cancel := context.WithCancel(ctx)
defer cancel()
for blob := range r.idx.Each(ctx) {
invalidIndex := false
r.idx.Each(ctx, func(blob restic.PackedBlob) {
if blob.IsCompressed() {
return errors.Fatal("index uses feature not supported by repository version 1")
invalidIndex = true
}
})
if invalidIndex {
return errors.Fatal("index uses feature not supported by repository version 1")
}
}