From c608679963e9abeebad050ff9715e23e99648ad8 Mon Sep 17 00:00:00 2001 From: Hai | RISE <150876604+hai-rise@users.noreply.github.com> Date: Sat, 7 Dec 2024 03:38:20 +0700 Subject: [PATCH] perf(`AllTransactions`-iter): do not clone all transactions by default (#13187) --- crates/transaction-pool/src/pool/mod.rs | 17 ++++++++++++++--- crates/transaction-pool/src/pool/txpool.rs | 6 +++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index c13dca17de01..d93b4a14d80c 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -295,7 +295,7 @@ where /// Returns _all_ transactions in the pool. pub fn pooled_transactions(&self) -> Vec>> { - self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).collect() + self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).cloned().collect() } /// Returns only the first `max` transactions in the pool. @@ -303,7 +303,13 @@ where &self, max: usize, ) -> Vec>> { - self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).take(max).collect() + self.get_pool_data() + .all() + .transactions_iter() + .filter(|tx| tx.propagate) + .take(max) + .cloned() + .collect() } /// Converts the internally tracked transaction to the pooled format. @@ -857,7 +863,12 @@ where &self, origin: TransactionOrigin, ) -> Vec>> { - self.get_pool_data().all().transactions_iter().filter(|tx| tx.origin == origin).collect() + self.get_pool_data() + .all() + .transactions_iter() + .filter(|tx| tx.origin == origin) + .cloned() + .collect() } /// Returns all pending transactions filted by [`TransactionOrigin`] diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 7dd64da73645..1b330543cffa 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1095,11 +1095,11 @@ impl AllTransactions { self.by_hash.keys().copied() } - /// Returns an iterator over all _unique_ hashes in the pool + /// Returns an iterator over all transactions in the pool pub(crate) fn transactions_iter( &self, - ) -> impl Iterator>> + '_ { - self.by_hash.values().cloned() + ) -> impl Iterator>> + '_ { + self.by_hash.values() } /// Returns if the transaction for the given hash is already included in this pool