From b622989463f1b6c666b2de1ebbbbbc3af0c9cb54 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 15 Apr 2025 20:04:46 +0700 Subject: [PATCH] perf: optimize version bit calculation Result of `calculateStartHeight` is not always used but it's always calculated --- src/versionbits.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/versionbits.cpp b/src/versionbits.cpp index 04168f416c7d..5dd584895c74 100644 --- a/src/versionbits.cpp +++ b/src/versionbits.cpp @@ -73,6 +73,9 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* assert(cache.count(pindexPrev)); ThresholdState state = cache[pindexPrev]; + // we should avoid heavy calculation of nStartHeight below if there's nothing to compute + if (vToCompute.empty()) return state; + int nStartHeight = calculateStartHeight(pindexPrev, state, nPeriod, cache); // Now walk forward and compute the state of descendants of pindexPrev