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 <steven@stebalien.com>
Steven Allen committed
Oct 11, 2017 at 11:43 UTC
9de031b432003cd2a086677f19f240744a30a236
1 file changed
+3
-2
merkledag/batch.go
+3
-2
@@ -43,7 +43,8 @@ func (t *Batch) processResults() {
43
}
44
45
func (t *Batch) asyncCommit() {
46
- if len(t.blocks) == 0 || t.commitError != nil {
46
+ numBlocks := len(t.blocks)
47
+ if numBlocks == 0 || t.commitError != nil {
48
return
49
}
50
if t.activeCommits >= ParallelBatchCommits {
@@ -61,7 +62,7 @@ func (t *Batch) asyncCommit() {
62
}(t.blocks)
63
64
t.activeCommits++
64
- t.blocks = nil
65
+ t.blocks = make([]blocks.Block, 0, numBlocks)
66
t.size = 0
67
68
return