use pooled slices for the copy
This commit is contained in:
parent
b741d61b20
commit
001c04f2dd
@ -342,6 +342,20 @@ func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) erro
|
||||
iter := txn.NewIterator(opts)
|
||||
defer iter.Close()
|
||||
|
||||
pooled := make([][]byte, 0, 2*moveBatchSize)
|
||||
getPooled := func(size int) []byte {
|
||||
buf := pool.Get(size)
|
||||
pooled = append(pooled, buf)
|
||||
return buf
|
||||
}
|
||||
putPooled := func() {
|
||||
for _, buf := range pooled {
|
||||
pool.Put(buf)
|
||||
}
|
||||
pooled = pooled[:0]
|
||||
}
|
||||
defer putPooled()
|
||||
|
||||
var buf []byte
|
||||
for iter.Rewind(); iter.Valid(); iter.Next() {
|
||||
if !b.isOpen() {
|
||||
@ -350,8 +364,9 @@ func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) erro
|
||||
|
||||
item := iter.Item()
|
||||
|
||||
kk := item.Key()
|
||||
if filter != nil {
|
||||
k := item.Key()
|
||||
k := kk
|
||||
if b.prefixing {
|
||||
k = k[b.prefixLen:]
|
||||
}
|
||||
@ -372,8 +387,15 @@ func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) erro
|
||||
}
|
||||
}
|
||||
|
||||
k := item.KeyCopy(nil)
|
||||
v, err := item.ValueCopy(nil)
|
||||
k := getPooled(len(kk))
|
||||
copy(k, kk)
|
||||
|
||||
var v []byte
|
||||
err := item.Value(func(vv []byte) error {
|
||||
v = getPooled(len(vv))
|
||||
copy(v, vv)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -388,6 +410,7 @@ func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) erro
|
||||
return err
|
||||
}
|
||||
count = 0
|
||||
putPooled()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user