r/cpp • • Feb 16 '26

Favorite optimizations ??

I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!

133 Upvotes

185 comments sorted by

View all comments

Show parent comment

9

u/rdtsc Feb 16 '26

How is this determined? PGO?

7

u/SlightlyLessHairyApe Feb 17 '26

PGO helps, but there's good results manually with the usual __builtin_expect family of functions that have been around since forever.

2

u/matthieum Feb 17 '26

I don't think PGO is strictly necessary.

At the interface level, [[noreturn]] is a big one, and inter-procedural analysis can extrapolate it from throw, or by propagating it from [[noreturn]] functions such as abort.

LTO & PGO will help, obviously, when it's necessary to reach to another TU / library.