Improve AccountID string conversion caching:

Caching the base58check encoded version of an `AccountID` has
performance advantages, because because of the computationally
heavy cost associated with the conversion, which requires the
application of SHA-256 twice.

This commit makes the cache significantly more efficient in terms
of memory used: it eliminates the map, using a vector with a size
that is determined by the configured size of the node, and a hash
function to directly map any given `AccountID` to a specific slot
in the cache; the eviction policy is simple: in case of collision
the existing entry is removed and replaced with the new data.

Previously, use of the cache was optional and required additional
effort by the programmer. Now the cache is automatic and does not
require any additional work or information.

The new cache also utilizes a 64-way spinlock, to help reduce any
contention that the pressure on the cache would impose.
This commit is contained in:
Nik Bougalis
2022-05-25 11:22:47 -07:00
parent 5a15229eeb
commit e2eed966b0
21 changed files with 157 additions and 196 deletions

View File

@@ -181,7 +181,6 @@ public:
NodeStoreScheduler m_nodeStoreScheduler;
std::unique_ptr<SHAMapStore> m_shaMapStore;
PendingSaves pendingSaves_;
AccountIDCache accountIDCache_;
std::optional<OpenLedger> openLedger_;
NodeCache m_tempNodeCache;
@@ -336,8 +335,6 @@ public:
m_nodeStoreScheduler,
logs_->journal("SHAMapStore")))
, accountIDCache_(128000)
, m_tempNodeCache(
"NodeCache",
16384,
@@ -494,6 +491,8 @@ public:
config_->reporting() ? std::make_unique<ReportingETL>(*this)
: nullptr)
{
initAccountIdCache(config_->getValueFor(SizedItem::accountIdCacheSize));
add(m_resourceManager.get());
//
@@ -856,12 +855,6 @@ public:
return pendingSaves_;
}
AccountIDCache const&
accountIDCache() const override
{
return accountIDCache_;
}
OpenLedger&
openLedger() override
{