fix(explorer): commit the loadRangeCached/revision memoization the perf fix depends on
Repairs dev:3ee9099switched the Explorer call sites (and a test) to ExplorerBlockCache::loadRangeCached() / revision(), but those definitions were sitting uncommitted in the working tree (left over from the explorer block-search feature,ebbeb84) and were not staged with that commit — so dev as pushed referenced undefined members and would not compile on a clean checkout. The infra: loadRangeCached() memoizes loadRange() per (min,max), invalidated by revision_, which is bumped on every mutation that can change what loadRange returns (open/close/store/clear/prune/spill-reset); the memo is capped at 16 ranges. My local builds passed only because the working tree already had these. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct sqlite3;
|
||||
@@ -44,6 +45,11 @@ public:
|
||||
const std::string& databasePath() const { return database_path_; }
|
||||
|
||||
std::map<int, ExplorerBlockSummary> loadRange(int minHeight, int maxHeight);
|
||||
// loadRange memoized per (min,max) and invalidated by revision() so the per-frame Explorer list only hits SQLite
|
||||
// after the cache actually changed (store / clear / prune / spill reset / open / close). The reference is valid
|
||||
// until the next call; copy it if you call again before using it.
|
||||
const std::map<int, ExplorerBlockSummary>& loadRangeCached(int minHeight, int maxHeight);
|
||||
std::uint64_t revision() const { return revision_; }
|
||||
// Fuzzy search over cached blocks: matches when the query is a substring of the height (as text)
|
||||
// or the block hash (case-insensitive). Returns newest-first, capped at `limit`.
|
||||
std::vector<ExplorerBlockSummary> searchBlocks(const std::string& query, int limit);
|
||||
@@ -102,6 +108,11 @@ private:
|
||||
int open_attempts_ = 0;
|
||||
int stores_since_prune_ = 0;
|
||||
|
||||
// Bumped by every mutation that can change what loadRange returns; keys the loadRangeCached memo.
|
||||
std::uint64_t revision_ = 1;
|
||||
std::uint64_t range_cache_revision_ = 0;
|
||||
std::map<std::pair<int, int>, std::map<int, ExplorerBlockSummary>> range_cache_;
|
||||
|
||||
// Blocks the DB refused, bounded and UI-thread only. Evicts the entry farthest from the last spilled height
|
||||
// (the Explorer fetches around the visible window). Cleared with clearBlocks() and when the chain tip regresses.
|
||||
static constexpr std::size_t kMaxSpillBlocks = 512;
|
||||
|
||||
Reference in New Issue
Block a user