From: Cherry Mui Date: Fri, 4 Nov 2022 01:22:44 +0000 (-0400) Subject: cmd/compile/internal/pgo: check repeated edge only when node is seen X-Git-Tag: go1.20rc1~413 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f187c6b08eac9dddd161bb2e7537def3bbf8ec9a;p=gostls13.git 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 --- 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) }