From b767ffbda2c90c180dc4f3869cd6605f7b9119c5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 7 Jun 2025 17:11:30 +0200 Subject: [PATCH] perf: remove redundant clones (#16716) --- crates/rpc/rpc-eth-types/src/fee_history.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/rpc/rpc-eth-types/src/fee_history.rs b/crates/rpc/rpc-eth-types/src/fee_history.rs index da67e92dcd..0425a38629 100644 --- a/crates/rpc/rpc-eth-types/src/fee_history.rs +++ b/crates/rpc/rpc-eth-types/src/fee_history.rs @@ -74,8 +74,8 @@ impl FeeHistoryCache { async fn insert_blocks<'a, I, B, R, C>(&self, blocks: I, chain_spec: &C) where B: Block + 'a, - R: TxReceipt, - I: IntoIterator, Arc>)>, + R: TxReceipt + 'a, + I: IntoIterator, &'a [R])>, C: EthChainSpec, { let mut entries = self.inner.entries.write().await; @@ -92,7 +92,7 @@ impl FeeHistoryCache { fee_history_entry.gas_used, fee_history_entry.base_fee_per_gas, block.body().transactions(), - &receipts, + receipts, ) .unwrap_or_default(); entries.insert(block.number(), fee_history_entry); @@ -241,7 +241,7 @@ pub async fn fee_history_cache_new_blocks_task( res = &mut fetch_missing_block => { if let Ok(res) = res { let res = res.as_ref() - .map(|(b, r)| (b.sealed_block(), r.clone())); + .map(|(b, r)| (b.sealed_block(), r.as_slice())); fee_history_cache.insert_blocks(res, &chain_spec).await; } } @@ -252,13 +252,12 @@ pub async fn fee_history_cache_new_blocks_task( }; let committed = event.committed(); - let (blocks, receipts): (Vec<_>, Vec<_>) = committed + let blocks_and_receipts = committed .blocks_and_receipts() .map(|(block, receipts)| { - (block.clone_sealed_block(), Arc::new(receipts.clone())) - }) - .unzip(); - fee_history_cache.insert_blocks(blocks.iter().zip(receipts), &chain_spec).await; + (block.sealed_block(), receipts.as_slice()) + }); + fee_history_cache.insert_blocks(blocks_and_receipts, &chain_spec).await; // keep track of missing blocks missing_blocks = fee_history_cache.missing_consecutive_blocks().await;