Skip to content

Commit 38513b6

Browse files
committed
perf: temporary cache for consequent calls of CDeterministicMNList for historical blocks
It speeds ups blocks's Undo up to 10x. It speeds up RPC `protx diff` up to 9x
1 parent 690a1cd commit 38513b6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/evo/deterministicmns.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,13 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlockInternal(gsl::not_n
778778
for (const auto& diffIndex : listDiffIndexes) {
779779
const auto& diff = mnListDiffsCache.at(diffIndex->GetBlockHash());
780780
snapshot.ApplyDiff(diffIndex, diff);
781+
if (snapshot.GetHeight() % 32 == 0) {
782+
// Add this temporary mini-snapshot to cache.
783+
// This extra cached mn-list helps to improve performance of GetListForBlock
784+
// for close blocks, because in the worst cases each of them requires to retrieve
785+
// and apply up to 575 diffs
786+
mnListsCache.emplace(snapshot.GetBlockHash(), snapshot);
787+
}
781788
}
782789

783790
if (tipIndex) {

0 commit comments

Comments
 (0)