Description
I spent some time evaluating a potential state caching mechanism that would allow some speedups in run time. This issue documents the results in case we want to do it in the future, or weigh the feature against other development options.
The core idea is that Medusa can potentially cache state databases, keying them based on H(starting merkle root | txhash)
. We should probably also key this using the block+timestamp delay, but I only wanted to MVP it for this exploration.
Since many transaction sequences are generated from the corpus, this would theoretically allow us to cache the state transition function that gets executed relatively often.
The biggest unknowns are how much of a speedup this would actually offer, and how much memory would be consumed.
I empirically determined the estimated speedup by adding some monitoring logic to EVMApplyTransaction
. In the best case, 30% of calls to EVMApplyTransaction can be served from the state cache. In the average case, it's closer to 20-25%. This does not include the time it takes to populate and retrieve entries from the cache, so we should consider this as no better than a 25% speedup in the best case (assuming most of our execution overhead is EVMApplyTransaction).
Didn't explore how much memory would be consumed. If state caches are direct copies of the statedb, expect dozens or even hundreds of kilobytes for each cache entry. If state caches are journal-like objects, then maybe it would be a lot less, but with more time required to "retrieve" from cache.
I also didn't measure how much time EVMApplyTransaction consumes as part of the normal fuzzing session. This should be measured because it might be a lot less than we expect.