-
Notifications
You must be signed in to change notification settings - Fork 27
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
perf(client, host): redundant state caching #59
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your point on the witnessdb -- this is a really good catch that will probably save a lot of cycles. Left some small nits, also going to ask in the revm telegram any performance differences between database and databaseref. Because at this point, maybe we can just make WitnessDB a Database instead of DatabaseRef, but I'm not sure how good that is.
crates/executor/host/src/lib.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an unused import in this file according to the linter
crates/storage/rpc-db/src/lib.rs
Outdated
use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; | ||
use revm_primitives::HashMap; | ||
|
||
/// A database that fetches data from a [Provider] over a [Transport]. | ||
/// | ||
/// This type is very similar to a CacheDb as exposed by revm, except we have some extra fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can say that the caching part is similar, but the RpcDB actually uses an RPC to fetch the state, which is pretty different from the CacheDB which is just a wrapper.
adjusted comment + lint |
I think compared to the current wrapper it'll save a deref |
Background
Typically,
CacheDb
is used when reads from the underlyingExtDB
are expensive. This cache represents the state at the beginning of the block, any state changes actually happen in a wrapper around theDB: Database
type.Internally CacheDB just stores queries in a memory map.
Client
In the client,
CacheDB
will make everything more expensive because the underlying witnessdb is really cheap to read from, soCacheDB
does a clone that is not needed for every read.Host
In the host, the
RpcDB
type does almost everything theCacheDB
would do, this means. things like storage slots are saved twice in memory.With minimal changes
RpcDB
we can replicate all theCacheDB
behavior, and instead implDatabase
and we can pass a &mut of it to the executor.