[Optimization] Add caching for Clarity contracts - ContractContext
, source code & ContractAnalysis
#4444
Labels
ContractContext
, source code & ContractAnalysis
#4444
Contracts and their properties, source code, analyses, which are otherwise static data once a contract has been installed, are read+deserialized a number of times during the execution of a contract.
Implement a simple, node-global LRU cache for these objects in their deserialized form to optimize access for:
The contracts should be cached (keyed) according to their canonicalized epoch, i.e. a contract canonicalized in both 2.05 and 2.4 would have two entries. So the key would be a tuple of
⚠️ I'm making the assumption that this is possible, particularly when processing cross-epoch transactions? If not, then the contract can be keyed on its identifier alone.
(<qualified contract identifier>, <epoch>)
.The cache shouldn't be large, just enough to help avoid disk reads and extra deserializations in the short-term. Suggestion at 100 contracts and 100 analyses (which we can make configurable).
ℹ️ The suggested implementation is
LruCache
from the lru crate. This crate is already used as a transient dependency viarusqlite
as part of their query cache, so the dependency graph will not become larger.The text was updated successfully, but these errors were encountered: