repository: Reduce buffer reallocations in ForAllIndexes

Previously the buffer was grown incrementally inside `repo.LoadUnpacked`.
But we can do better as we already know how large the index will be.
Allocate a bit more memory to increase the chance that the buffer can be
reused in the future.
This commit is contained in:
Michael Eischer 2022-08-19 21:11:02 +02:00
parent 77b1980d8e
commit 7a992fc794
1 changed files with 4 additions and 0 deletions

View File

@ -52,6 +52,10 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
var idx *Index
oldFormat := false
if cap(buf) < int(fi.Size) {
// overallocate a bit
buf = make([]byte, fi.Size+128*1024)
}
buf, err = repo.LoadUnpacked(ctx, restic.IndexFile, fi.ID, buf[:0])
if err == nil {
idx, oldFormat, err = DecodeIndex(buf, fi.ID)