Merge pull request #3989 from greatroar/eachbypack

More compact data structure for Index.EachByPack
This commit is contained in:
Michael Eischer 2022-10-30 00:02:55 +02:00 committed by GitHub
commit c7ace314f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -252,21 +252,18 @@ func (idx *Index) EachByPack(ctx context.Context, packBlacklist restic.IDSet) <-
go func() {
defer idx.m.Unlock()
defer func() {
close(ch)
}()
defer close(ch)
byPack := make(map[restic.ID][][]*indexEntry)
byPack := make(map[restic.ID][restic.NumBlobTypes][]*indexEntry)
for typ := range idx.byType {
m := &idx.byType[typ]
m.foreach(func(e *indexEntry) bool {
packID := idx.packs[e.packIndex]
if !idx.final || !packBlacklist.Has(packID) {
if _, ok := byPack[packID]; !ok {
byPack[packID] = make([][]*indexEntry, restic.NumBlobTypes)
}
byPack[packID][typ] = append(byPack[packID][typ], e)
v := byPack[packID]
v[typ] = append(v[typ], e)
byPack[packID] = v
}
return true
})
@ -281,7 +278,7 @@ func (idx *Index) EachByPack(ctx context.Context, packBlacklist restic.IDSet) <-
}
}
// allow GC once entry is no longer necessary
byPack[packID] = nil
delete(byPack, packID)
select {
case <-ctx.Done():
return

View File

@ -127,6 +127,8 @@ func benchmarkSaveAndEncrypt(t *testing.B, version uint) {
rtest.OK(t, err)
id := restic.ID(sha256.Sum256(data))
var wg errgroup.Group
repo.StartPackUploader(context.Background(), &wg)
t.ReportAllocs()
t.ResetTimer()