Skip to content

Commit

Permalink
preallocate Batch's blocks buffer on commit.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stebalien committed Oct 11, 2017
1 parent e41848c commit 9de031b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions merkledag/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 9de031b

Please sign in to comment.