mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
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>
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user