Skip to content

Commit 005369b

Browse files
authored
perf: optimize remove_invalidated_orders (#38)
Reduced from two passes (collect + retain) to a single pass by directly filtering during retention. This eliminates the intermediate HashSet allocation and simplifies the logic.
1 parent f8f44b4 commit 005369b

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/pool/maintain.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This is not a public API, but rather a set of utilities that are used
44
//! internally by the order pool to maintain its state and react to events.
55
6-
use {super::*, futures::StreamExt, std::collections::HashSet};
6+
use {super::*, futures::StreamExt};
77

88
impl<P: Platform> OrderPool<P> {
99
/// Removes orders that became permanently ineligible after the given block
@@ -12,25 +12,13 @@ impl<P: Platform> OrderPool<P> {
1212
&self,
1313
header: &SealedHeader<types::Header<P>>,
1414
) {
15-
let ineligible = self
16-
.inner
17-
.orders
18-
.iter()
19-
.filter_map(|order| {
20-
if let Order::Bundle(bundle) = order.value()
21-
&& bundle.is_permanently_ineligible(header)
22-
{
23-
Some(*order.key())
24-
} else {
25-
None
26-
}
27-
})
28-
.collect::<HashSet<_>>();
29-
30-
self
31-
.inner
32-
.orders
33-
.retain(|order_hash, _| !ineligible.contains(order_hash));
15+
self.inner.orders.retain(|_, order| {
16+
if let Order::Bundle(bundle) = order {
17+
!bundle.is_permanently_ineligible(header)
18+
} else {
19+
true
20+
}
21+
});
3422
}
3523

3624
pub(super) fn start_pipeline_events_listener(

0 commit comments

Comments
 (0)