Around all of it

Whole-Program & Feedback-Directed Optimization

Seeing across module boundaries with LTO, and measuring before optimizing with PGO — including what an unrepresentative profile does to the result.

Whole-Program Optimization
▶ lab

Seeing every function at once turns three transformations from impossible to routine — cross-module inlining, devirtualization and dead-function elimination — by supplying the one thing separate compilation deliberately withheld: the rest of the program.

Q · What can a compiler do if it can see the whole program that it cannot do one file at a time?
Link-Time Optimization
▶ lab

LTO is a scheduling trick, not a new optimization: the compiler writes IR into object files instead of machine code, and the linker — the first component that has all of them — hands them back to the optimizer before generating any.

Q · What is `-flto` actually doing, and what is the difference between full LTO and ThinLTO?
Profile-Guided Optimization
▶ lab

Compile once with counters, run a realistic workload, feed the counts back, compile again. The optimizer stops guessing which branch is taken and which function is hot — and the largest real win is usually not what people expect.

Q · How does a compiler find out which paths are hot, and what does it do differently once it knows?
What a Profile Costs You
▶ lab

A profile is not neutral evidence. An unrepresentative one does not fail to help — it actively points the optimizer at the wrong code, and it decays quietly as the source moves underneath it.

Q · What can go wrong with profile-guided optimization, and when is a sampled profile the better choice?
Feedback-Directed Optimization
▶ lab

PGO and a JIT are the same idea run at different times. Both optimize from measured behavior; the only two things that differ are when the evidence is collected and whether a guard is needed to act on it.

Q · What do PGO and a JIT actually have in common, and what is the real difference between them?
The Compiler Is Also a Program With Performance Requirements
▶ lab

A compiler is judged on four axes that trade against each other — compile time, memory, incremental turnaround and generated code quality — and the first one changes how engineers work, not merely how long they wait.

Q · Why is my build slow, and what is the compiler actually trading away when it is fast?