routing: optimize path finding structures

distance map now holds the edge the current path is coming from,
removing the need for next map.

Both distance map and distanceHeap now hold pointers instead of the full
struct to reduce allocations and copies.

Both these changes reduced path finding time by ~5% and memory usage by
~2mb.
This commit is contained in:
Juan Pablo Civile
2019-08-24 22:52:13 -03:00
parent fc36df0e60
commit df70095ad0
3 changed files with 28 additions and 31 deletions

View File

@@ -24,12 +24,12 @@ func TestHeapOrdering(t *testing.T) {
// Create 100 random entries adding them to the heap created above, but
// also a list that we'll sort with the entries.
const numEntries = 100
sortedEntries := make([]nodeWithDist, 0, numEntries)
sortedEntries := make([]*nodeWithDist, 0, numEntries)
for i := 0; i < numEntries; i++ {
var pubKey [33]byte
prand.Read(pubKey[:])
entry := nodeWithDist{
entry := &nodeWithDist{
node: route.Vertex(pubKey),
dist: prand.Int63(),
}
@@ -55,9 +55,9 @@ func TestHeapOrdering(t *testing.T) {
// One by one, pop of all the entries from the heap, they should come
// out in sorted order.
var poppedEntries []nodeWithDist
var poppedEntries []*nodeWithDist
for nodeHeap.Len() != 0 {
e := heap.Pop(&nodeHeap).(nodeWithDist)
e := heap.Pop(&nodeHeap).(*nodeWithDist)
poppedEntries = append(poppedEntries, e)
}