From 103bca1ba7cae631d90c803be396dcfbe9d587f8 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sun, 16 Jun 2019 12:07:35 +0300 Subject: [PATCH] LoadBlockIndexDB speed-up for non-LWMAPOS chains (x5 perfomance boost) seems we had CChainPower classes compare here from Verus, it's slow, bcz of hard arith_uint256 math in bool operator<(const CChainPower &p1, const CChainPower &p2), this slows down setBlockIndexCandidates.insert operations in LoadBlockIndexDB(), so, for faster block index db loading we will use check from Verus only for LWMAPOS enabled chains. perfomance test (daemon load time from start): without fix - 3m42sec with fix - 39sec --- src/main.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 30783e2ab..e01cba61f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,10 +147,28 @@ namespace { struct CBlockIndexWorkComparator { - bool operator()(CBlockIndex *pa, CBlockIndex *pb) const { + bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const { // First sort by most total work, ... - if (pa->chainPower > pb->chainPower) return false; - if (pa->chainPower < pb->chainPower) return true; + + if (ASSETCHAINS_LWMAPOS) { + + /* Decker: + + seems we had CChainPower classes compare here from Verus, it's slow, bcz of hard + arith_uint256 math in bool operator<(const CChainPower &p1, const CChainPower &p2), + this slows down setBlockIndexCandidates.insert operations in LoadBlockIndexDB(), + so, for faster block index db loading we will use check from Verus only for LWMAPOS + enabled chains. + */ + + if (pa->chainPower > pb->chainPower) return false; + if (pa->chainPower < pb->chainPower) return true; + } + else + { + if (pa->chainPower.chainWork > pb->chainPower.chainWork) return false; + if (pa->chainPower.chainWork < pb->chainPower.chainWork) return true; + } // ... then by earliest time received, ... if (pa->nSequenceId < pb->nSequenceId) return false; @@ -173,8 +191,10 @@ namespace { * as good as our current tip or better. Entries may be failed, though, and pruning nodes may be * missing the data for the block. */ + + //set> setBlockIndexCandidates; set setBlockIndexCandidates; - + /** Number of nodes with fSyncStarted. */ int nSyncStarted = 0;