Skip to content

Commit 583a161

Browse files
perf: pre-allocate BinaryHeap in astar_bag
Add capacity hint to reduce reallocations in astar_bag BinaryHeap, similar to the optimization already done for regular astar function. Co-authored-by: samueltardieu <44656+samueltardieu@users.noreply.github.com>
1 parent 110d172 commit 583a161

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/directed/astar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ where
185185
FH: FnMut(&N) -> C,
186186
FS: FnMut(&N) -> bool,
187187
{
188-
let mut to_see = BinaryHeap::new();
188+
// Pre-allocate heap with a reasonable default capacity to reduce reallocations
189+
let mut to_see = BinaryHeap::with_capacity(64);
189190
let mut min_cost = None;
190191
let mut sinks = HashSet::new();
191192
to_see.push(SmallestCostHolder {

0 commit comments

Comments
 (0)