diff options
| author | Michael Pratt <mpratt@google.com> | 2024-03-04 13:29:39 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-03-27 20:20:01 +0000 |
| commit | 63deaf00ea6058d1422f0b435e475666cba5743e (patch) | |
| tree | 20ea11d36b1c627fd99993ea6eaff8835e698ffc /src/cmd/compile/internal/devirtualize | |
| parent | 2860e01853174e278900ef6907b1941b16fb1645 (diff) | |
| download | go-63deaf00ea6058d1422f0b435e475666cba5743e.tar.xz | |
cmd/compile,cmd/preprofile: move logic to shared common package
The processing performed in cmd/preprofile is a simple version of the
same initial processing performed by cmd/compile/internal/pgo. Refactor
this processing into the new IR-independent cmd/internal/pgo package.
Now cmd/preprofile and cmd/compile run the same code for initial
processing of a pprof profile, guaranteeing that they always stay in
sync.
Since it is now trivial, this CL makes one change to the serialization
format: the entries are ordered by weight. This allows us to avoid
sorting ByWeight on deserialization.
Impact on PGO parsing when compiling cmd/compile with PGO:
* Without preprocessing: PGO parsing ~13.7% of CPU time
* With preprocessing (unsorted): ~2.9% of CPU time (sorting ~1.7%)
* With preprocessing (sorted): ~1.3% of CPU time
The remaining 1.3% of CPU time approximately breaks down as:
* ~0.5% parsing the preprocessed profile
* ~0.7% building weighted IR call graph
* ~0.5% walking function IR to find direct calls
* ~0.2% performing lookups for indirect calls targets
For #58102.
Change-Id: Iaba425ea30b063ca195fb2f7b29342961c8a64c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/569337
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/devirtualize')
| -rw-r--r-- | src/cmd/compile/internal/devirtualize/pgo_test.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/devirtualize/pgo_test.go b/src/cmd/compile/internal/devirtualize/pgo_test.go index 84c96df122..6ba8e9f907 100644 --- a/src/cmd/compile/internal/devirtualize/pgo_test.go +++ b/src/cmd/compile/internal/devirtualize/pgo_test.go @@ -7,10 +7,11 @@ package devirtualize import ( "cmd/compile/internal/base" "cmd/compile/internal/ir" - "cmd/compile/internal/pgo" + pgoir "cmd/compile/internal/pgo" "cmd/compile/internal/typecheck" "cmd/compile/internal/types" "cmd/internal/obj" + "cmd/internal/pgo" "cmd/internal/src" "testing" ) @@ -32,32 +33,32 @@ func makePos(b *src.PosBase, line, col uint) src.XPos { } type profileBuilder struct { - p *pgo.Profile + p *pgoir.Profile } func newProfileBuilder() *profileBuilder { - // findHotConcreteCallee only uses pgo.Profile.WeightedCG, so we're + // findHotConcreteCallee only uses pgoir.Profile.WeightedCG, so we're // going to take a shortcut and only construct that. return &profileBuilder{ - p: &pgo.Profile{ - WeightedCG: &pgo.IRGraph{ - IRNodes: make(map[string]*pgo.IRNode), + p: &pgoir.Profile{ + WeightedCG: &pgoir.IRGraph{ + IRNodes: make(map[string]*pgoir.IRNode), }, }, } } // Profile returns the constructed profile. -func (p *profileBuilder) Profile() *pgo.Profile { +func (p *profileBuilder) Profile() *pgoir.Profile { return p.p } // NewNode creates a new IRNode and adds it to the profile. // // fn may be nil, in which case the node will set LinkerSymbolName. -func (p *profileBuilder) NewNode(name string, fn *ir.Func) *pgo.IRNode { - n := &pgo.IRNode{ - OutEdges: make(map[pgo.NamedCallEdge]*pgo.IREdge), +func (p *profileBuilder) NewNode(name string, fn *ir.Func) *pgoir.IRNode { + n := &pgoir.IRNode{ + OutEdges: make(map[pgo.NamedCallEdge]*pgoir.IREdge), } if fn != nil { n.AST = fn @@ -69,13 +70,13 @@ func (p *profileBuilder) NewNode(name string, fn *ir.Func) *pgo.IRNode { } // Add a new call edge from caller to callee. -func addEdge(caller, callee *pgo.IRNode, offset int, weight int64) { +func addEdge(caller, callee *pgoir.IRNode, offset int, weight int64) { namedEdge := pgo.NamedCallEdge{ CallerName: caller.Name(), CalleeName: callee.Name(), CallSiteOffset: offset, } - irEdge := &pgo.IREdge{ + irEdge := &pgoir.IREdge{ Src: caller, Dst: callee, CallSiteOffset: offset, |
