-
Notifications
You must be signed in to change notification settings - Fork 16
Implement cached reads #75
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
Conversation
karim-agha
left a comment
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.
looks great!
src/payload/ext/cached_state.rs
Outdated
| cache.insert_storage(key, Some(value)); | ||
| } | ||
| }); | ||
| println!( |
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.
| println!( | |
| info!( |
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.
to make it work with TEST_TRACE=on test logging
src/payload/ext/cached_state.rs
Outdated
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// use reth_revm::{cached::CachedReads, DatabaseRef, db::State}; |
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.
Update rustdoc
src/payload/ext/cached_state.rs
Outdated
| #[test] | ||
| fn measure_storage_cache_overhead() { | ||
| let (base_overhead, cache) = | ||
| measure_allocation(|| AccountStorageCache::new()); | ||
| info!("Base AccountStorageCache overhead: {base_overhead} bytes"); | ||
| let mut rng = rand::rng(); | ||
|
|
||
| let key = StorageKey::random(); | ||
| let value = StorageValue::from(rng.random::<u128>()); | ||
| let (first_slot, _) = measure_allocation(|| { | ||
| cache.insert_storage(key, Some(value)); | ||
| }); | ||
| info!("First slot insertion overhead: {first_slot} bytes"); | ||
|
|
||
| const TOTAL_SLOTS: usize = 10_000; | ||
| let (test_slots, _) = measure_allocation(|| { | ||
| for _ in 0..TOTAL_SLOTS { | ||
| let key = StorageKey::random(); | ||
| let value = StorageValue::from(rng.random::<u128>()); | ||
| cache.insert_storage(key, Some(value)); | ||
| } | ||
| }); | ||
| info!( | ||
| "Average overhead over {} slots: {} bytes", | ||
| TOTAL_SLOTS, | ||
| test_slots / TOTAL_SLOTS | ||
| ); | ||
|
|
||
| info!("\nTheoretical sizes:"); | ||
| info!("StorageKey size: {} bytes", size_of::<StorageKey>()); | ||
| info!("StorageValue size: {} bytes", size_of::<StorageValue>()); | ||
| info!( | ||
| "Option<StorageValue> size: {} bytes", | ||
| size_of::<Option<StorageValue>>() | ||
| ); | ||
| info!("Option<B256> size: {} bytes", size_of::<Option<B256>>()); | ||
| } |
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.
Should we keep this as test?
src/payload/block.rs
Outdated
| // TODO: Prefill execution_cached with bundle state from the previous block | ||
| let execution_cached = ExecutionCache::default(); |
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.
We can add a cache: Option<ExecutionCache> as argument.
And we can handle passing cache across blocks at the pipeline level
Implement layer of caching for state, prefilled with previous block bundle state.
Probably we don't need DashMap and could use HashMap, would be refactored later, once we see more concrete usage examples