Skip to content

Commit 3baee7b

Browse files
sipacodablock
authored andcommitted
Merge bitcoin#8681: Performance Regression Fix: Pre-Allocate txChanged vector
ec81881 Performance Regression Fix: Pre-Allocate txChanged vector (Jeremy Rubin)
1 parent 0324fa0 commit 3baee7b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/validation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ static int64_t nTimePostConnect = 0;
25742574
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
25752575
* corresponding to pindexNew, to bypass loading it again from disk.
25762576
*/
2577-
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)
2577+
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)
25782578
{
25792579
assert(pindexNew->pprev == chainActive.Tip());
25802580
// Read block from disk.
@@ -2615,7 +2615,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
26152615
UpdateTip(pindexNew, chainparams);
26162616

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

26202620
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
26212621
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
@@ -2740,7 +2740,7 @@ static void PruneBlockIndexCandidates() {
27402740
* Try to make some progress towards making pindexMostWork the active block.
27412741
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
27422742
*/
2743-
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)
2743+
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)
27442744
{
27452745
AssertLockHeld(cs_main);
27462746
const CBlockIndex *pindexOldTip = chainActive.Tip();
@@ -2842,14 +2842,17 @@ static void NotifyHeaderTip() {
28422842
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
28432843
CBlockIndex *pindexMostWork = NULL;
28442844
CBlockIndex *pindexNewTip = NULL;
2845+
std::vector<std::tuple<CTransaction,CBlockIndex*,int>> txChanged;
2846+
if (pblock)
2847+
txChanged.reserve(pblock->vtx.size());
28452848
do {
2849+
txChanged.clear();
28462850
boost::this_thread::interruption_point();
28472851
if (ShutdownRequested())
28482852
break;
28492853

28502854
const CBlockIndex *pindexFork;
28512855
std::list<CTransaction> txConflicted;
2852-
std::vector<std::tuple<CTransaction,CBlockIndex*,int> > txChanged;
28532856
bool fInitialDownload;
28542857
{
28552858
LOCK(cs_main);

0 commit comments

Comments
 (0)