pool: preallocate pool3
This commit is contained in:
parent
a8959fe60e
commit
9c72c02502
@ -58,9 +58,9 @@ type TxPool3Heap struct {
|
||||
sequence uint64 // Monotonically increasing sequence number
|
||||
}
|
||||
|
||||
func NewTxPool3Heap() *TxPool3Heap {
|
||||
func NewTxPool3Heap(estimatedMaxSize uint64) *TxPool3Heap {
|
||||
return &TxPool3Heap{
|
||||
txHeap: make(txHeap, 0),
|
||||
txHeap: make(txHeap, 0, estimatedMaxSize),
|
||||
index: make(map[common.Hash]*txHeapItem),
|
||||
sequence: 0,
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func createTestTx(nonce uint64, gasPrice *big.Int) *types.Transaction {
|
||||
}
|
||||
|
||||
func TestNewTxPool3Heap(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
if pool == nil {
|
||||
t.Fatal("NewTxPool3Heap returned nil")
|
||||
}
|
||||
@ -28,7 +28,7 @@ func TestNewTxPool3Heap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapAdd(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
tx := createTestTx(1, big.NewInt(1000))
|
||||
|
||||
pool.Add(tx)
|
||||
@ -44,7 +44,7 @@ func TestTxPool3HeapAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapGet(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
tx := createTestTx(1, big.NewInt(1000))
|
||||
pool.Add(tx)
|
||||
|
||||
@ -63,7 +63,7 @@ func TestTxPool3HeapGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapRemove(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
tx := createTestTx(1, big.NewInt(1000))
|
||||
pool.Add(tx)
|
||||
|
||||
@ -80,7 +80,7 @@ func TestTxPool3HeapRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapPopN(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
tx1 := createTestTx(1, big.NewInt(1000))
|
||||
tx2 := createTestTx(2, big.NewInt(2000))
|
||||
tx3 := createTestTx(3, big.NewInt(3000))
|
||||
@ -116,7 +116,7 @@ func TestTxPool3HeapPopN(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapOrdering(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
tx1 := createTestTx(1, big.NewInt(1000))
|
||||
tx2 := createTestTx(2, big.NewInt(2000))
|
||||
tx3 := createTestTx(3, big.NewInt(3000))
|
||||
@ -136,7 +136,7 @@ func TestTxPool3HeapOrdering(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxPool3HeapLen(t *testing.T) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
if pool.Len() != 0 {
|
||||
t.Errorf("New pool should have length 0, got %d", pool.Len())
|
||||
}
|
||||
@ -173,7 +173,7 @@ func createRandomTestTx() *types.Transaction {
|
||||
// pkg: github.com/ethereum/go-ethereum/core/txpool/legacypool
|
||||
// BenchmarkTxPool3HeapAdd-8 45870 24270 ns/op
|
||||
func BenchmarkTxPool3HeapAdd(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
tx := createRandomTestTx()
|
||||
@ -183,7 +183,7 @@ func BenchmarkTxPool3HeapAdd(b *testing.B) {
|
||||
|
||||
// BenchmarkTxPool3HeapGet-8 34522438 37.05 ns/op
|
||||
func BenchmarkTxPool3HeapGet(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
txs := make([]*types.Transaction, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
tx := createRandomTestTx()
|
||||
@ -198,7 +198,7 @@ func BenchmarkTxPool3HeapGet(b *testing.B) {
|
||||
|
||||
// BenchmarkTxPool3HeapRemove-8 2643650 539.2 ns/op
|
||||
func BenchmarkTxPool3HeapRemove(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
txs := make([]*types.Transaction, b.N)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tx := createRandomTestTx()
|
||||
@ -213,7 +213,7 @@ func BenchmarkTxPool3HeapRemove(b *testing.B) {
|
||||
|
||||
// BenchmarkTxPool3HeapPopN-8 47899808 23.80 ns/op
|
||||
func BenchmarkTxPool3HeapPopN(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
for i := 0; i < 1000; i++ {
|
||||
tx := createRandomTestTx()
|
||||
pool.Add(tx)
|
||||
@ -226,7 +226,7 @@ func BenchmarkTxPool3HeapPopN(b *testing.B) {
|
||||
|
||||
// BenchmarkTxPool3HeapLen-8 86149902 13.32 ns/op
|
||||
func BenchmarkTxPool3HeapLen(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
for i := 0; i < 1000; i++ {
|
||||
tx := createRandomTestTx()
|
||||
pool.Add(tx)
|
||||
@ -239,7 +239,7 @@ func BenchmarkTxPool3HeapLen(b *testing.B) {
|
||||
|
||||
// BenchmarkTxPool3HeapAddRemove-8 46156 25019 ns/op
|
||||
func BenchmarkTxPool3HeapAddRemove(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
tx := createRandomTestTx()
|
||||
@ -251,7 +251,7 @@ func BenchmarkTxPool3HeapAddRemove(b *testing.B) {
|
||||
// BenchmarkTxPool3HeapAddPopN-8 470 2377928 ns/op pool.PopN(100)
|
||||
// BenchmarkTxPool3HeapAddPopN-8 4694 285026 ns/op pool.PopN(10)
|
||||
func BenchmarkTxPool3HeapAddPopN(b *testing.B) {
|
||||
pool := NewTxPool3Heap()
|
||||
pool := NewTxPool3Heap(0)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for j := 0; j < 10; j++ {
|
||||
|
@ -279,7 +279,7 @@ func New(config Config, chain BlockChain) *LegacyPool {
|
||||
reorgDoneCh: make(chan chan struct{}),
|
||||
reorgShutdownCh: make(chan struct{}),
|
||||
initDoneCh: make(chan struct{}),
|
||||
localBufferPool: NewTxPool3Heap(),
|
||||
localBufferPool: NewTxPool3Heap(config.Pool3Slots),
|
||||
}
|
||||
pool.locals = newAccountSet(pool.signer)
|
||||
for _, addr := range config.Locals {
|
||||
|
Loading…
Reference in New Issue
Block a user