CosmWasm / cosmwasm

Framework for building smart contracts in Wasm for the Cosmos SDK
https://www.cosmwasm.com/
Apache License 2.0
1.07k stars 338 forks source link

Evaluate different cache replacement policies for InMemoryCache #742

Open maurolacy opened 3 years ago

maurolacy commented 3 years ago

Currently used LRU is probably not the best choice. For a blockchain, a LFU or some time-aware variant like LRFU (or the next few on the list) could be more appropriate.

As it is much easier to game LRU and flush popular items out of the cache

I don't know a way to simulate it both for efficiency in normal use and stability in face of byzantine actors, but a thought experiment over a few algorithms and searching for ones with good rust implementations should be a good start.

maurolacy commented 3 years ago

List of "popular" (>1000 downloads) cache crates (in decreasing order of popularity):

Also interesting / relevant:

Documenting this list for when we decide to do this task.

aumetra commented 2 months ago

Another viable caching algorithm would probably be an implementation of the SIEVE algorithm, a refinement of CLOCK IIRC: https://cachemon.github.io/SIEVE-website/