Skip to content

Commit 245cca7

Browse files
authored
perf: avoid collect in truncate_pool (#20221)
1 parent 28d6996 commit 245cca7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

crates/transaction-pool/src/identifier.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl SenderId {
6666
std::ops::Bound::Included(TransactionId::new(self, 0))
6767
}
6868

69+
/// Returns a `Range` for [`TransactionId`] starting with nonce `0` and ending with nonce
70+
/// `u64::MAX`
71+
pub const fn range(self) -> std::ops::RangeInclusive<TransactionId> {
72+
TransactionId::new(self, 0)..=TransactionId::new(self, u64::MAX)
73+
}
74+
6975
/// Converts the sender to a [`TransactionId`] with the given nonce.
7076
pub const fn into_transaction_id(self, nonce: u64) -> TransactionId {
7177
TransactionId::new(self, nonce)

crates/transaction-pool/src/pool/parked.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ impl<T: ParkedOrd> ParkedPool<T> {
186186
{
187187
// NOTE: This will not panic due to `!last_sender_transaction.is_empty()`
188188
let sender_id = self.last_sender_submission.last().unwrap().sender_id;
189-
let list = self.get_txs_by_sender(sender_id);
190189

191190
// Drop transactions from this sender until the pool is under limits
192-
for txid in list.into_iter().rev() {
193-
if let Some(tx) = self.remove_transaction(&txid) {
191+
while let Some((tx_id, _)) = self.by_id.range(sender_id.range()).next_back() {
192+
let tx_id = *tx_id;
193+
if let Some(tx) = self.remove_transaction(&tx_id) {
194194
removed.push(tx);
195195
}
196196

0 commit comments

Comments
 (0)