From: Michael Pratt Date: Tue, 12 Sep 2023 18:23:15 +0000 (-0400) Subject: cmd/compile/internal/devirtualize: sort equal weight CallStat.Hottest by name X-Git-Tag: go1.22rc1~880 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4b17b36b3f0ea85728d8690c93a6483764804441;p=gostls13.git cmd/compile/internal/devirtualize: sort equal weight CallStat.Hottest by name When two callees have equal weight, we need to sort by another criteria to ensure that we get stable output. Note that this is only for the CallStat debug JSON output. The actual callee selection already does this secondary sort in findHotConcreteCallee. Change-Id: I0de105623c5ccc793ca6f5799ea25e57bc286722 Reviewed-on: https://go-review.googlesource.com/c/go/+/527796 Auto-Submit: Michael Pratt Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/devirtualize/pgo.go b/src/cmd/compile/internal/devirtualize/pgo.go index 800b32f6eb..b51028701e 100644 --- a/src/cmd/compile/internal/devirtualize/pgo.go +++ b/src/cmd/compile/internal/devirtualize/pgo.go @@ -223,6 +223,18 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx offset := pgo.NodeLineOffset(call, fn) + hotter := func(e *pgo.IREdge) bool { + if stat.Hottest == "" { + return true + } + if e.Weight != stat.HottestWeight { + return e.Weight > stat.HottestWeight + } + // If weight is the same, arbitrarily sort lexicographally, as + // findHotConcreteCallee does. + return e.Dst.Name() < stat.Hottest + } + // Sum of all edges from this callsite, regardless of callee. // For direct calls, this should be the same as the single edge // weight (except for multiple calls on one line, which we @@ -233,7 +245,7 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx continue } stat.Weight += edge.Weight - if edge.Weight > stat.HottestWeight { + if hotter(edge) { stat.HottestWeight = edge.Weight stat.Hottest = edge.Dst.Name() }