From 1615806e1d33691a8a2712c4ddb1c2589b1ac3e2 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Sat, 31 Jan 2026 14:38:22 +0800 Subject: [PATCH] perf(state): avoid unnecessary clone, prealloc, and fix typo --- crates/state/src/bal/account.rs | 19 +++++++++++-------- crates/state/src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/state/src/bal/account.rs b/crates/state/src/bal/account.rs index 6ca4b7458a..a442bc94ed 100644 --- a/crates/state/src/bal/account.rs +++ b/crates/state/src/bal/account.rs @@ -96,8 +96,9 @@ impl AccountBal { /// Consumes AccountBal and converts it into [`AlloyAccountChanges`]. #[inline] pub fn into_alloy_account(self, address: Address) -> AlloyAccountChanges { - let mut storage_reads = Vec::new(); - let mut storage_changes = Vec::new(); + let storage_len = self.storage.storage.len(); + let mut storage_reads = Vec::with_capacity(storage_len); + let mut storage_changes = Vec::with_capacity(storage_len); for (key, value) in self.storage.storage { if value.writes.is_empty() { storage_reads.push(key); @@ -180,12 +181,14 @@ impl AccountInfoBal { self.nonce.update(index, &original.nonce, present.nonce); self.balance .update(index, &original.balance, present.balance); - self.code.update_with_key( - index, - &original.code_hash, - (present.code_hash, present.code.clone().unwrap_or_default()), - |i| &i.0, - ); + if original.code_hash != present.code_hash { + self.code.update_with_key( + index, + &original.code_hash, + (present.code_hash, present.code.clone().unwrap_or_default()), + |i| &i.0, + ); + } } /// Extend account info from another account info. diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index f857b36688..79571d72c8 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -39,7 +39,7 @@ pub struct Account { pub info: AccountInfo, /// Original account info used by BAL, changed only on cold load by BAL. pub original_info: Box, - /// Transaction id, used to track when account was toched/loaded into journal. + /// Transaction id, used to track when account was touched/loaded into journal. pub transaction_id: usize, /// Storage cache pub storage: EvmStorage,