From f187c6b08eac9dddd161bb2e7537def3bbf8ec9a Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 3 Nov 2022 21:22:44 -0400 Subject: [PATCH] cmd/compile/internal/pgo: check repeated edge only when node is seen When adding weights for a call stack, for recursive calls, to avoid double counting we check if we already saw the node and the edge. We check the node first. An edge can be repeated if the node is repeated. Most stacks are not recursive, so check repeated edge only conditionally. Change-Id: I4b8f039289dcd3383ca89593d6d16d903b94c3dd Reviewed-on: https://go-review.googlesource.com/c/go/+/447804 TryBot-Result: Gopher Robot Run-TryBot: Cherry Mui Reviewed-by: Michael Pratt --- src/cmd/compile/internal/pgo/graph.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/pgo/graph.go b/src/cmd/compile/internal/pgo/graph.go index 193100897d..d422d5b097 100644 --- a/src/cmd/compile/internal/pgo/graph.go +++ b/src/cmd/compile/internal/pgo/graph.go @@ -282,12 +282,13 @@ func newGraph(prof *profile.Profile, o *Options) (*Graph, map[uint64]Nodes) { continue } // Add cum weight to all nodes in stack, avoiding double counting. - if _, ok := seenNode[n]; !ok { + _, sawNode := seenNode[n] + if !sawNode { seenNode[n] = true n.addSample(dw, w, false) } // Update edge weights for all edges in stack, avoiding double counting. - if _, ok := seenEdge[nodePair{n, parent}]; !ok && parent != nil && n != parent { + if (!sawNode || !seenEdge[nodePair{n, parent}]) && parent != nil && n != parent { seenEdge[nodePair{n, parent}] = true parent.AddToEdgeDiv(n, dw, w, residual, ni != len(locNodes)-1) } -- 2.50.0