From 137f0bc9448c00533abf78aea11e70dbb0c1c677 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:21:24 +0200 Subject: [PATCH 1/2] repository: Fix benchmarkSaveAndEncrypt --- internal/repository/repository_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 7b5789605..f4be16cbc 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -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() From 0e8893dae97be667fea2c0724fcf8be1f4f8346c Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:57:52 +0200 Subject: [PATCH 2/2] index: Compact data structure for Index.EachByPack --- internal/index/index.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/index/index.go b/internal/index/index.go index 507f1a564..420f52544 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -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