From fc36df0e606cdeb98c0aca1a2831da36aa728bb4 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Sat, 24 Aug 2019 20:02:43 -0300 Subject: [PATCH] routing: avoid unneeded map access `processEdge` basically had 4 expensive operations: 3 map accesses and updating the heap. This removes one of those for a small performance gain. --- routing/pathfind.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index e3e457cf..8a67ccf1 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -552,7 +552,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, // better than the current best known distance to this node. // The new better distance is recorded, and also our "next hop" // map is populated with this edge. - distance[fromVertex] = nodeWithDist{ + withDist := nodeWithDist{ dist: tempDist, weight: tempWeight, node: fromVertex, @@ -560,13 +560,14 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, incomingCltv: incomingCltv, probability: probability, } + distance[fromVertex] = withDist next[fromVertex] = edge - // Either push distance[fromVertex] onto the heap if the node + // Either push withDist onto the heap if the node // represented by fromVertex is not already on the heap OR adjust // its position within the heap via heap.Fix. - nodeHeap.PushOrFix(distance[fromVertex]) + nodeHeap.PushOrFix(withDist) } // TODO(roasbeef): also add path caching