]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/pgo: check repeated edge only when node is seen
authorCherry Mui <cherryyz@google.com>
Fri, 4 Nov 2022 01:22:44 +0000 (21:22 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 4 Nov 2022 21:19:24 +0000 (21:19 +0000)
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 <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/compile/internal/pgo/graph.go

index 193100897d11903f5df89143cd50e7bbf80a3d59..d422d5b0974a4e2d36034b114ebc8c556e57cb95 100644 (file)
@@ -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)
                                }