-
Notifications
You must be signed in to change notification settings - Fork 624
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
Save all visited nodes into cache on block level #5920
Comments
It May or not be relevant, but with the new SDK collections, accesses are cached to avoid duplicate access, so this change might only be beneficial for Aurora and anyone accessing storage manually. I suppose that if the accesses are cached per block, it may help if multiple other txs access duplicate keys, but unsure if the overhead of having the cache and potential increase of cost of this would offset. |
Hey @austinabell, this is interesting! Could you give some examples? I'm curious how it can be cached, because if cache touches contract storage, I don't see how it can avoid touching trie nodes. |
Yeah, so in |
Update: some further investigation showed that among all the trie nodes touched, only 10% of them are unique, which means that if we cache all trie nodes visited during the execution of a transaction/receipt, we can potentially save 90% of the touching trie node cost for transactions that do a lot of storage reads and writes. See https://near.zulipchat.com/#narrow/stream/295558-nearinc.2Fprotocol-core/topic/touching.20trie.20node.20counter/near/267074859 for more details. |
This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. |
Done in #6628. |
Idea
[Investigation](https://near.zulipchat.com/#narrow/stream/308695-near-eng-private/topic/trie.20depth/near/263925418) of some Aurora call shows that 30-40% gas is spent on touching trie node, and 38% of these nodes are top-level ones. So we just charge for taking the same nodes from DB again and again, which is suboptimal.
At the same time, in
TrieUpdate
we storecommitted
andprospective
changes which work as cache with key-value modificaions in the current block. If we save all intermediate nodes, we could theoretically save ~13% of current Aurora costs.Caveats
Trie::lookup
TrieCache
storing recent touched nodes. However, it is not accounted by the protocol.TrieUpdate
must store updates only for one block (I may be imprecise here). So it can't be easily extendedAdditional context
Because of the last caveat, we could consider implementing cache on transaction level, e.g. LRU cache storing last nodes queried by last X transactions. It makes more sense, but should be implemented from scratch and it also should be as simple as possible.
The text was updated successfully, but these errors were encountered: