Skip to content

Conversation

@SozinM
Copy link
Collaborator

@SozinM SozinM commented Nov 20, 2025

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

Copy link
Collaborator

@karim-agha karim-agha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

cache.insert_storage(key, Some(value));
}
});
println!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!(
info!(

Copy link
Collaborator

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

/// # Example
///
/// ```
/// use reth_revm::{cached::CachedReads, DatabaseRef, db::State};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update rustdoc

Comment on lines 524 to 560
#[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>>());
}
Copy link
Collaborator

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?

Comment on lines 84 to 85
// TODO: Prefill execution_cached with bundle state from the previous block
let execution_cached = ExecutionCache::default();
Copy link
Collaborator

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

@SozinM SozinM merged commit 3e57981 into main Nov 24, 2025
4 checks passed
@SozinM SozinM deleted the msozin/cached-state-provider branch November 24, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants