From 9de031b432003cd2a086677f19f240744a30a236 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 11 Oct 2017 11:43:30 -0700 Subject: [PATCH] preallocate Batch's blocks buffer on commit. It's probably safe to assume that this buffer will be about the same time each flush. This could cause 1 extra allocation (if this is the last commit) but that's unlikely to be an issue. License: MIT Signed-off-by: Steven Allen --- merkledag/batch.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/merkledag/batch.go b/merkledag/batch.go index bf3e74048..b6dd286b9 100644 --- a/merkledag/batch.go +++ b/merkledag/batch.go @@ -43,7 +43,8 @@ func (t *Batch) processResults() { } func (t *Batch) asyncCommit() { - if len(t.blocks) == 0 || t.commitError != nil { + numBlocks := len(t.blocks) + if numBlocks == 0 || t.commitError != nil { return } if t.activeCommits >= ParallelBatchCommits { @@ -61,7 +62,7 @@ func (t *Batch) asyncCommit() { }(t.blocks) t.activeCommits++ - t.blocks = nil + t.blocks = make([]blocks.Block, 0, numBlocks) t.size = 0 return