From a56b8fad87cc8faaf3d9e3b312c752b3b7902bc2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 8 Apr 2018 21:57:52 +0200 Subject: [PATCH] repository: Improve buffer pooling --- internal/repository/pool.go | 2 +- internal/repository/repository.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/repository/pool.go b/internal/repository/pool.go index 9c7450d5c..b87791f14 100644 --- a/internal/repository/pool.go +++ b/internal/repository/pool.go @@ -8,7 +8,7 @@ import ( var bufPool = sync.Pool{ New: func() interface{} { - return make([]byte, chunker.MinSize) + return make([]byte, chunker.MaxSize/3) }, } diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 3a1ce40c2..4a76f4025 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -214,11 +214,11 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data // get buf from the pool ciphertext := getBuf() - defer freeBuf(ciphertext) ciphertext = ciphertext[:0] nonce := crypto.NewRandomNonce() ciphertext = append(ciphertext, nonce...) + defer freeBuf(ciphertext) // encrypt blob ciphertext = r.key.Seal(ciphertext, nonce, data, nil)