perf: make truncate_pool no-op if pending is under limits (#6706)

This commit is contained in:
Dan Cline
2024-02-21 03:29:19 -05:00
committed by GitHub
parent 2eef0dc1a5
commit 86788c618c

View File

@ -455,13 +455,19 @@ impl<T: TransactionOrdering> PendingPool<T> {
limit: SubPoolLimit,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
let mut removed = Vec::new();
self.remove_to_limit(&limit, false, &mut removed);
// return early if the pool is already under the limits
if !limit.is_exceeded(self.len(), self.size()) {
return removed
}
// now repeat for local transactions
// first truncate only non-local transactions, returning if the pool end up under the limit
self.remove_to_limit(&limit, false, &mut removed);
if !limit.is_exceeded(self.len(), self.size()) {
return removed
}
// now repeat for local transactions, since local transactions must be removed now for the
// pool to be under the limit
self.remove_to_limit(&limit, true, &mut removed);
removed