diff options
author | Martin Holst Swende <martin@swende.se> | 2018-01-31 01:03:31 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-01-31 01:03:31 +0800 |
commit | 017b9f7eacd1048661b22b7892caf680deb2b548 (patch) | |
tree | e94115fdb225e7da6fe046fde71ce0e53bb15b23 | |
parent | 6198c53e28200b3a575f4545cbfa83c585e44b76 (diff) | |
download | go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar.gz go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar.bz2 go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar.lz go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar.xz go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.tar.zst go-tangerine-017b9f7eacd1048661b22b7892caf680deb2b548.zip |
core, ethdb: reuse database batches (#15989)
* leveldb: Update leveldb to 211f780 (poolfix)
* core, ethdb: reuse database batches
-rw-r--r-- | core/blockchain.go | 2 | ||||
-rw-r--r-- | ethdb/database.go | 8 | ||||
-rw-r--r-- | ethdb/interface.go | 2 | ||||
-rw-r--r-- | ethdb/memory_database.go | 5 |
4 files changed, 16 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index f886ffe4e..1bda95231 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -749,7 +749,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ return 0, err } bytes += batch.ValueSize() - batch = bc.chainDb.NewBatch() + batch.Reset() } } if batch.ValueSize() > 0 { diff --git a/ethdb/database.go b/ethdb/database.go index 93755dd7e..9a7c85d9e 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -299,6 +299,10 @@ func (b *ldbBatch) ValueSize() int { return b.size } +func (b *ldbBatch) Reset() { + b.b.Reset() +} + type table struct { db Database prefix string @@ -358,3 +362,7 @@ func (tb *tableBatch) Write() error { func (tb *tableBatch) ValueSize() int { return tb.batch.ValueSize() } + +func (tb *tableBatch) Reset() { + tb.batch.Reset() +} diff --git a/ethdb/interface.go b/ethdb/interface.go index 99a5b770d..537312003 100644 --- a/ethdb/interface.go +++ b/ethdb/interface.go @@ -41,4 +41,6 @@ type Batch interface { Putter ValueSize() int // amount of data in the batch Write() error + // Reset resets the batch for reuse + Reset() } diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index 0dd93a279..8efd7bf84 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -123,3 +123,8 @@ func (b *memBatch) Write() error { func (b *memBatch) ValueSize() int { return b.size } + +func (b *memBatch) Reset() { + b.writes = b.writes[:0] + b.size = 0 +} |