-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make use of state cache when building blocks for a parachain #9770
Comments
For caching accesses during block building, I think the easiest model would be to have a trie node cache. |
Good idea! We should implement an early version and compare that against the state cache. Even if there is a small performance hit,I think we should switch to a trie level cache. The point here being is that parachains currently can not use the state cache for block building and the state cache is rather complicated. Another bonus point of a trie cache would be that we would solve #9769 as well. |
Drafted such cache in this branch : master...cheme:trie_state_cache |
@cheme do we have a benchmark for comparing state-cache vs trie-cache? |
In theory on my branch switching values in https://github.com/cheme/substrate/blob/b23b1a11b17e480d8d4ade4c77f87ffddd1979a1/bin/node/testing/src/bench.rs#L381 should apply to bench, but I am not familiar enough with the bench to say. |
Can you try to run it and compare it against master? |
I will check syncing this afternoon, but would be good a bench specialist points to relevant benchmarks. |
@arkpar do you know which benchmark we could use for this? |
There's no benchmark specifically for the block building that I'm aware of. We could try replacing the storage cache with the trie cache and simply compare importing 100k blocks of an existing parachain with an |
I did run 100k first blocks polkadot import, but I did not really see difference (on my pc it's about 3:45min for all scenario (even for no cache at all)). So I guess first 100k blocks are being a bit empty.
But I did run the bench locally and there is strong chance I may have interfere with it. |
@cheme could you prepare a polkadot branch? And then we do multiple syncs with state-cache/without/with trie-cache? The state-cache issues are getting more and more pressing, so I would like to switch as fast as possible. However, if you are currently to overwhelmed by the trie migration stuff, I will find someone else. |
That's good, trie stuff is a bit pending review, and I think it will be mainly updating the branch from my previous message. |
What is good? So should I ask someone else? This needs to be done asap |
I mean I will prepare a branch (today). |
@bkchr this polkadot branch is usable: https://github.com/cheme/polkadot-1/tree/trie_state_cache One possible cause of performance regression could be the absence of |
I have written a benchmark:
I tried some optimizations in the trie code, however, I think we will never get to the same level as the state cache. There is just too much "happening" when using the trie. So, I will try to rewrite the state cache using overlays. |
That looks quite good! (Ignore that without cache is also faster, because it currently also uses this new cache). However, I think that is good enough to switch to it. We can maybe do some more optimizations in the future, but for now this should be good enough. |
from the latest benchmark result of |
The |
Latest benchmark results:
|
When we are building blocks for a parachain, we also need to collect a state proof. This means that we will trigger a different code path that currently doesn't support the state cache when we build a block for a parachain.
This code path is taken when building a parachain block:
https://github.com/paritytech/substrate/blob/master/client/service/src/client/call_executor.rs#L234-L260
And this particular call: https://github.com/paritytech/substrate/blob/master/client/service/src/client/call_executor.rs#L234 (as_trie_backend) prevents that we use the state cache.
The text was updated successfully, but these errors were encountered: