optimization: store just IDs of child nodes

IDs are a lot smaller, hence quicker to manage.
Any time we want to refer back to the full node we look it up in its topology.

(This relies on nobody trying to store a rendered node as a child).
This commit is contained in:
Bryan Boreham
2020-06-08 16:39:50 +00:00
parent b4a73b7f87
commit d76da767d8
13 changed files with 233 additions and 280 deletions

View File

@@ -161,8 +161,7 @@ type joinResults struct {
func newJoinResults(inputNodes report.Nodes) joinResults {
nodes := make(report.Nodes, len(inputNodes))
for id, n := range inputNodes {
n.Adjacency = nil // result() assumes all nodes start with no adjacencies
n.Children = n.Children.Copy() // so we can do unsafe adds
n.Adjacency = nil // result() assumes all nodes start with no adjacencies
nodes[id] = n
}
return joinResults{nodes: nodes, mapped: map[string]string{}, multi: map[string][]string{}}
@@ -193,7 +192,7 @@ func (ret *joinResults) addUnmappedChild(m report.Node, id string, topology stri
if !exists {
result = report.MakeNode(id).WithTopology(topology)
}
result.Children.UnsafeAdd(m)
result = result.WithChildID(m.ID)
if m.Topology != report.Endpoint { // optimisation: we never look at endpoint counts
result = result.AddCounter(m.Topology, 1)
}
@@ -212,7 +211,7 @@ func (ret *joinResults) addChild(m report.Node, id string, topology string) {
func (ret *joinResults) addChildAndChildren(m report.Node, id string, topology string) {
ret.addUnmappedChild(m, id, topology)
result := ret.nodes[id]
result.Children.UnsafeMerge(m.Children)
result = result.WithChildren(m.ChildIDs)
ret.nodes[id] = result
ret.mapChild(m.ID, id)
}
@@ -221,7 +220,6 @@ func (ret *joinResults) addChildAndChildren(m report.Node, id string, topology s
func (ret *joinResults) passThrough(n report.Node) {
n.Adjacency = nil // result() assumes all nodes start with no adjacencies
ret.nodes[n.ID] = n
n.Children = n.Children.Copy() // so we can do unsafe adds
ret.mapChild(n.ID, n.ID)
}