Skip to content

Commit 962d223

Browse files
author
MarcoFalke
committed
bench: Move constructors out of mempool_eviction hot loop
1 parent 6b46288 commit 962d223

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include <list>
1010
#include <vector>
1111

12-
static void AddTx(const CMutableTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
12+
static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool)
1313
{
1414
int64_t nTime = 0;
1515
unsigned int nHeight = 1;
1616
bool spendsCoinbase = false;
1717
unsigned int sigOpCost = 4;
1818
LockPoints lp;
19-
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
20-
MakeTransactionRef(tx), nFee, nTime, nHeight,
21-
spendsCoinbase, sigOpCost, lp));
19+
pool.addUnchecked(tx->GetHash(), CTxMemPoolEntry(
20+
tx, nFee, nTime, nHeight,
21+
spendsCoinbase, sigOpCost, lp));
2222
}
2323

2424
// Right now this is only testing eviction performance in an extremely small
@@ -97,15 +97,23 @@ static void MempoolEviction(benchmark::State& state)
9797
tx7.vout[1].nValue = 10 * COIN;
9898

9999
CTxMemPool pool;
100+
// Create transaction references outside the "hot loop"
101+
const CTransactionRef tx1_r{MakeTransactionRef(tx1)};
102+
const CTransactionRef tx2_r{MakeTransactionRef(tx2)};
103+
const CTransactionRef tx3_r{MakeTransactionRef(tx3)};
104+
const CTransactionRef tx4_r{MakeTransactionRef(tx4)};
105+
const CTransactionRef tx5_r{MakeTransactionRef(tx5)};
106+
const CTransactionRef tx6_r{MakeTransactionRef(tx6)};
107+
const CTransactionRef tx7_r{MakeTransactionRef(tx7)};
100108

101109
while (state.KeepRunning()) {
102-
AddTx(tx1, 10000LL, pool);
103-
AddTx(tx2, 5000LL, pool);
104-
AddTx(tx3, 20000LL, pool);
105-
AddTx(tx4, 7000LL, pool);
106-
AddTx(tx5, 1000LL, pool);
107-
AddTx(tx6, 1100LL, pool);
108-
AddTx(tx7, 9000LL, pool);
110+
AddTx(tx1_r, 10000LL, pool);
111+
AddTx(tx2_r, 5000LL, pool);
112+
AddTx(tx3_r, 20000LL, pool);
113+
AddTx(tx4_r, 7000LL, pool);
114+
AddTx(tx5_r, 1000LL, pool);
115+
AddTx(tx6_r, 1100LL, pool);
116+
AddTx(tx7_r, 9000LL, pool);
109117
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
110118
pool.TrimToSize(GetVirtualTransactionSize(tx1));
111119
}

0 commit comments

Comments
 (0)