mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 23:21:12 +02:00
routing: pre-allocate the distance map to an estimated node count
Pre-sizing these structures avoids a lot of map resizing, which causes copies and rehashing of entries. We mostly know that the map won't exceed that size, and it doesn't affect memory usage in any significant way.
This commit is contained in:
@@ -50,9 +50,10 @@ type distanceHeap struct {
|
||||
|
||||
// newDistanceHeap initializes a new distance heap. This is required because
|
||||
// we must initialize the pubkeyIndices map for path-finding optimizations.
|
||||
func newDistanceHeap() distanceHeap {
|
||||
func newDistanceHeap(numNodes int) distanceHeap {
|
||||
distHeap := distanceHeap{
|
||||
pubkeyIndices: make(map[route.Vertex]int),
|
||||
pubkeyIndices: make(map[route.Vertex]int, numNodes),
|
||||
nodes: make([]nodeWithDist, 0, numNodes),
|
||||
}
|
||||
|
||||
return distHeap
|
||||
|
Reference in New Issue
Block a user