cosmos / cosmos-sdk

:chains: A Framework for Building High Value Public Blockchains :sparkles:
https://cosmos.network/
Apache License 2.0
6.24k stars 3.61k forks source link

[Feature (collections)]: decoded object cache #19223

Open tac0turtle opened 8 months ago

tac0turtle commented 8 months ago

Summary

As we deprecate the context due to the design of server/v2 we will need modules to fetch data from the consensus module if they need the consensus params. this poises an new overhead.

Problem Definition

Asking users to fetch data from other modules means there is another layer of decoding needing to happen. In the case of context params they would need to fetch it from consensus, while it may already be in the cache, it will need to be decoded each time.

Proposed Feature

Add a way object cache to be used with collections so items that are repeatedly fetched from other modules will be stored in this cache already decoded. The cache would need to be flushed upon every write.

This is somewhat similar to interblock cache except, the change is that the values will already be decoded. We should avoid doing this for all state but for values that are touched repeatedly in a block this would reduce the over head.

Future Optimisations: If we have a way to prefetch keys from store we could decode them ahead of time there fore reducing the total time of execution by avoiding the fetch and decode in the execution path.

alexanderbez commented 8 months ago

If I'm reading this correctly, the proposal is to have an (unlimited sized) cache that stores typed objects (collections) and will be purged/cleared at the end of every block, right?

tac0turtle commented 8 months ago

yea something like that. the application dev should make the decision to cache it or not. Ideally its not automatic

tac0turtle commented 4 months ago

we should look at how cronos does it and implemnt the same for store v2 https://github.com/crypto-org-chain/cosmos-sdk/pull/206