golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.89k stars 17.52k forks source link

cmd/compile: PGO compiler diagnostics #58153

Open prattmic opened 1 year ago

prattmic commented 1 year ago

Today, the compiler has some limited diagnostics of behavior with PGO using the -d=pgoinline=1 flag. These are really just ad-hoc logging points. We want more robust diagnostics, for reasons @josharian lays out well in https://github.com/golang/go/issues/55022#issuecomment-1246155126:

The more opaque the toolchain and its inputs are, the harder it is to (a) write safety checks that detect performance problems before they make it to production and (b) diagnose performance issues after they make it to production.

Plus (c) of making it easier for us to investigate compilers issues filed here.

Our current thinking for initial work here is to provide more complete/structured output of all optimization decisions, rather than just "decisions due to PGO", because the latter is ambiguous. e.g., if we decide to do an inline because of PGO and that affects the non-PGO heuristics further up the call tree, does that count as a "PGO" decision.

cc @cherrymui @aclements

prattmic commented 1 year ago

Bumping to 1.22. There is more structural work to be done.

For 1.21, PGO devirtualization does include structured JSON output with -d=pgodebug=3 detailing every single call with its type (direct, indirect interface, etc) and whether it was devirtualized. That can then be used for external analysis (e.g., with a tool like https://go.dev/cl/494717).

gopherbot commented 1 year ago

Change https://go.dev/cl/528400 mentions this issue: cmd/compile: add pgohash for debugging/bisecting PGO optimizations

prattmic commented 12 months ago

Minor change: -m differentiates PGO vs static devirtualization, but doesn't note PGO-enabled inlines (-d=pgodebug=1 is required for that).