Skip to content

Commit

Permalink
perf(trie): init hashed storage only on existing **changed** slots (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Nov 28, 2024
1 parent ae395e8 commit da53d76
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,20 @@ where
let info = if account.is_empty() { None } else { Some(account.info.into()) };
hashed_state_update.accounts.insert(hashed_address, info);

if destroyed || !account.storage.is_empty() {
let storage = HashedStorage::from_iter(
destroyed,
account.storage.into_iter().filter_map(|(slot, value)| {
value
.is_changed()
.then(|| (keccak256(B256::from(slot)), value.present_value))
}),
let mut changed_storage_iter = account
.storage
.into_iter()
.filter_map(|(slot, value)| {
value
.is_changed()
.then(|| (keccak256(B256::from(slot)), value.present_value))
})
.peekable();
if destroyed || changed_storage_iter.peek().is_some() {
hashed_state_update.storages.insert(
hashed_address,
HashedStorage::from_iter(destroyed, changed_storage_iter),
);
hashed_state_update.storages.insert(hashed_address, storage);
}
}
}
Expand Down

0 comments on commit da53d76

Please sign in to comment.