golang / go

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

cmd/compile: add intra-line discrimination to PGO profiles #59612

Open prattmic opened 1 year ago

prattmic commented 1 year ago

Currently the CPU pprof profiles used for PGO can only break down samples to the source line level. PCs are also included and more precise, but without the original binary they aren't very useful.

This places artificial limitations on the accuracy of optimizations. e.g., if there are two calls to the same function on the same line, we cannot distinguish which one is hot and which one is cold.

This is even more problematic for some potential optimizations. e.g., basic block level optimizations need basic block weights, but there may be multiple basic blocks on the same line.

There are two obvious choices for this: column numbers or "discriminators".

Column numbers have the advantage of being intuitive and with a stable meaning, but have the downside that some constructs that we'd like to differentiate may still share a column number. e.g., I believe that bounds check comparison, success, and failure (panic) cases all share the same column number.

Discriminators have the advantage of flexibility. The compiler can assign them arbitrarily to every construct we care about. The main downside is potential instability. If two compiler versions generate different discriminator values, then profiles aren't fully compatible across the upgrade.

The pprof format itself does not support either column numbers or discriminators, so they will need to be added somehow.

cc @cherrymui @aclements @rajbarik @jinlin-bayarea

gopherbot commented 7 months ago

Change https://go.dev/cl/560781 mentions this issue: PROTOTYPE: cmd/compile,runtime: add discriminator, plumb to pprof