Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(AllTransactions-iter): do not clone all transactions by default #13187

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,21 @@ where

/// Returns _all_ transactions in the pool.
pub fn pooled_transactions(&self) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
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.
pub fn pooled_transactions_max(
&self,
max: usize,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
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.
Expand Down Expand Up @@ -857,7 +863,12 @@ where
&self,
origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
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`]
Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,11 @@ impl<T: PoolTransaction> AllTransactions<T> {
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<Item = Arc<ValidPoolTransaction<T>>> + '_ {
self.by_hash.values().cloned()
) -> impl Iterator<Item = &Arc<ValidPoolTransaction<T>>> + '_ {
self.by_hash.values()
Comment on lines +1101 to +1102
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, makes sense

}

/// Returns if the transaction for the given hash is already included in this pool
Expand Down
Loading