From 5ca4994c9c31228139317c4278e1868598a0b975 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 7 Nov 2018 14:57:41 +0000 Subject: rpc: speed up the common get_output_distribution case while syncing --- src/rpc/rpc_handler.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rpc/rpc_handler.cpp b/src/rpc/rpc_handler.cpp index 63664bf8b..e0a81c70f 100644 --- a/src/rpc/rpc_handler.cpp +++ b/src/rpc/rpc_handler.cpp @@ -43,8 +43,25 @@ namespace rpc std::vector distribution; std::uint64_t start_height, base; - if (!f(amount, from_height, to_height, start_height, distribution, base)) - return boost::none; + + // see if we can extend the cache - a common case + if (d.cached && amount == 0 && d.cached_from == from_height && to_height > d.cached_to) + { + std::vector new_distribution; + if (!f(amount, d.cached_to + 1, to_height, start_height, new_distribution, base)) + return boost::none; + distribution = d.cached_distribution; + distribution.reserve(distribution.size() + new_distribution.size()); + for (const auto &e: new_distribution) + distribution.push_back(e); + start_height = d.cached_start_height; + base = d.cached_base; + } + else + { + if (!f(amount, from_height, to_height, start_height, distribution, base)) + return boost::none; + } if (to_height > 0 && to_height >= from_height) { -- cgit v1.2.3