Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimization] Add caching for Clarity contracts - ContractContext, source code & ContractAnalysis #4444

Open
cylewitruk opened this issue Feb 28, 2024 · 0 comments
Assignees
Labels
optimization Update speed, efficiency, or quality of a feature. Size: 🐨 S (< 1 week)

Comments

@cylewitruk
Copy link
Member

cylewitruk commented Feb 28, 2024

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:

  1. Frequently used contracts (pox, bns, costs, etc.),
  2. Recently used contracts, to avoid needing to read the data multiple times from disk during a contract execution.

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 (<qualified contract identifier>, <epoch>).
⚠️ 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.

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 via rusqlite as part of their query cache, so the dependency graph will not become larger.

@cylewitruk cylewitruk added optimization Update speed, efficiency, or quality of a feature. enhancement Iterations on existing features or infrastructure. and removed enhancement Iterations on existing features or infrastructure. labels Feb 28, 2024
@cylewitruk cylewitruk changed the title [Enhancement] Add caching for Clarity contracts - ContractContext, source code & ContractAnalysis [Optimization] Add caching for Clarity contracts - ContractContext, source code & ContractAnalysis Feb 28, 2024
@cylewitruk cylewitruk self-assigned this Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Update speed, efficiency, or quality of a feature. Size: 🐨 S (< 1 week)
Projects
Status: Status: 🆕 New
Development

No branches or pull requests

1 participant