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:
parent
77b1980d8e
commit
7a992fc794
1 changed files with 4 additions and 0 deletions
|
@ -52,6 +52,10 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
|
||||||
var idx *Index
|
var idx *Index
|
||||||
oldFormat := false
|
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])
|
buf, err = repo.LoadUnpacked(ctx, restic.IndexFile, fi.ID, buf[:0])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
idx, oldFormat, err = DecodeIndex(buf, fi.ID)
|
idx, oldFormat, err = DecodeIndex(buf, fi.ID)
|
||||||
|
|
Loading…
Add table
Reference in a new issue