From 0fdddae9fcb290a66a9843d6cd857ba3f2646dbb Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Tue, 16 Jun 2020 11:53:57 -0400 Subject: [PATCH] Optimize DAG traversal in insertFrom --- snow/engine/avalanche/transitive.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/snow/engine/avalanche/transitive.go b/snow/engine/avalanche/transitive.go index e48b167..82ee859 100644 --- a/snow/engine/avalanche/transitive.go +++ b/snow/engine/avalanche/transitive.go @@ -335,10 +335,10 @@ func (t *Transitive) reinsertFrom(vdr ids.ShortID, vtxID ids.ID) (bool, error) { func (t *Transitive) insertFrom(vdr ids.ShortID, vtx avalanche.Vertex) (bool, error) { issued := true - vts := []avalanche.Vertex{vtx} - for len(vts) > 0 { - vtx := vts[0] - vts = vts[1:] + vertexHeap := newMaxVertexHeap() + vertexHeap.Push(vtx) + for vertexHeap.Len() > 0 { + vtx := vertexHeap.Pop() if t.Consensus.VertexIssued(vtx) { continue @@ -353,7 +353,7 @@ func (t *Transitive) insertFrom(vdr ids.ShortID, vtx avalanche.Vertex) (bool, er t.sendRequest(vdr, parent.ID()) issued = false } else { - vts = append(vts, parent) + vertexHeap.Push(parent) } }