mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 11:31:02 +00:00
5bf8769fb0
* trie: use pooling of iterator states in iterator The node iterator burns through a lot of memory while iterating a trie, and a lot of that can be avoided by using a fairly small pool (max 40 items). name old time/op new time/op delta Iterator-8 6.22ms ± 3% 5.40ms ± 6% -13.18% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Iterator-8 2.36MB ± 0% 1.67MB ± 0% -29.23% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Iterator-8 37.0k ± 0% 29.8k ± 0% ~ (p=0.079 n=4+5) * ethdb/memorydb: avoid one copying of key By making the transformation from []byte to string at an earlier point, we save an allocation which otherwise happens later on. name old time/op new time/op delta BatchAllocs-8 412µs ± 6% 382µs ± 2% -7.18% (p=0.016 n=5+4) name old alloc/op new alloc/op delta BatchAllocs-8 480kB ± 0% 490kB ± 0% +1.93% (p=0.008 n=5+5) name old allocs/op new allocs/op delta BatchAllocs-8 3.03k ± 0% 2.03k ± 0% -32.98% (p=0.008 n=5+5)
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
// Copyright 2018 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package memorydb
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/ethdb/dbtest"
|
|
)
|
|
|
|
func TestMemoryDB(t *testing.T) {
|
|
t.Run("DatabaseSuite", func(t *testing.T) {
|
|
dbtest.TestDatabaseSuite(t, func() ethdb.KeyValueStore {
|
|
return New()
|
|
})
|
|
})
|
|
}
|
|
|
|
// BenchmarkBatchAllocs measures the time/allocs for storing 120 kB of data
|
|
func BenchmarkBatchAllocs(b *testing.B) {
|
|
b.ReportAllocs()
|
|
var key = make([]byte, 20)
|
|
var val = make([]byte, 100)
|
|
// 120 * 1_000 -> 120_000 == 120kB
|
|
for i := 0; i < b.N; i++ {
|
|
batch := New().NewBatch()
|
|
for j := uint64(0); j < 1000; j++ {
|
|
binary.BigEndian.PutUint64(key, j)
|
|
binary.BigEndian.PutUint64(val, j)
|
|
batch.Put(key, val)
|
|
}
|
|
batch.Write()
|
|
}
|
|
}
|