From 556424d61ba8be128b85de8c53a58ebe8ddb5f18 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Thu, 20 Feb 2020 22:43:56 +0100 Subject: [PATCH] Reuse buffer in Restorer.VerifyFiles Time to verify a 2GB snapshot down from 11.568s to 9.726s (-16%). --- internal/restorer/restorer.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index b87a8a6f7..938be2b44 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + "github.com/restic/chunker" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/debug" @@ -316,8 +317,11 @@ func (res *Restorer) Snapshot() *restic.Snapshot { // including the file(s) that caused errors. func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) { // TODO multithreaded? + var ( + buf = make([]byte, 0, chunker.MaxSize) + count = 0 + ) - count := 0 _, err := res.traverseTree(ctx, dst, string(filepath.Separator), *res.sn.Tree, treeVisitor{ enterDir: func(node *restic.Node, target, location string) error { return nil }, visitNode: func(node *restic.Node, target, location string) error { @@ -342,7 +346,7 @@ func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) { offset := int64(0) for _, blobID := range node.Content { length, _ := res.repo.LookupBlobSize(blobID, restic.DataBlob) - buf := make([]byte, length) // TODO do I want to reuse the buffer somehow? + buf = buf[:length] _, err = file.ReadAt(buf, offset) if err != nil { _ = file.Close()