Skip to content

Commit 6898213

Browse files
committed
Merge #8681: Performance Regression Fix: Pre-Allocate txChanged vector
ec81881 Performance Regression Fix: Pre-Allocate txChanged vector (Jeremy Rubin)
2 parents 2abfe59 + ec81881 commit 6898213

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,7 @@ static int64_t nTimePostConnect = 0;
27872787
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
27882788
* corresponding to pindexNew, to bypass loading it again from disk.
27892789
*/
2790-
bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::list<CTransaction> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int> > &txChanged)
2790+
bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::list<CTransaction> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>> &txChanged)
27912791
{
27922792
assert(pindexNew->pprev == chainActive.Tip());
27932793
// Read block from disk.
@@ -2829,7 +2829,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
28292829
UpdateTip(pindexNew, chainparams);
28302830

28312831
for(unsigned int i=0; i < pblock->vtx.size(); i++)
2832-
txChanged.push_back(std::make_tuple(pblock->vtx[i], pindexNew, i));
2832+
txChanged.emplace_back(pblock->vtx[i], pindexNew, i);
28332833

28342834
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
28352835
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
@@ -2911,7 +2911,7 @@ static void PruneBlockIndexCandidates() {
29112911
* Try to make some progress towards making pindexMostWork the active block.
29122912
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
29132913
*/
2914-
static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::list<CTransaction>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int> >& txChanged)
2914+
static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::list<CTransaction>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>>& txChanged)
29152915
{
29162916
AssertLockHeld(cs_main);
29172917
const CBlockIndex *pindexOldTip = chainActive.Tip();
@@ -3013,14 +3013,17 @@ static void NotifyHeaderTip() {
30133013
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, const CBlock *pblock, CConnman* connman) {
30143014
CBlockIndex *pindexMostWork = NULL;
30153015
CBlockIndex *pindexNewTip = NULL;
3016+
std::vector<std::tuple<CTransaction,CBlockIndex*,int>> txChanged;
3017+
if (pblock)
3018+
txChanged.reserve(pblock->vtx.size());
30163019
do {
3020+
txChanged.clear();
30173021
boost::this_thread::interruption_point();
30183022
if (ShutdownRequested())
30193023
break;
30203024

30213025
const CBlockIndex *pindexFork;
30223026
std::list<CTransaction> txConflicted;
3023-
std::vector<std::tuple<CTransaction,CBlockIndex*,int> > txChanged;
30243027
bool fInitialDownload;
30253028
int nNewHeight;
30263029
{

0 commit comments

Comments
 (0)