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.
This commit is contained in:
Juan Pablo Civile 2019-08-24 20:02:43 -03:00
parent 3e60a23632
commit fc36df0e60

View File

@ -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