“Understanding Optimizers: Helping the Compiler Help You”
summary
Explains why compilers inline and when they won’t, with concrete examples: std::sort often turns a function pointer call into an indirect call but wrapping the function in a lambda usually forces inlining (GCC/Clang -O2/-O3); vector::clear can optimize away element destruction when destructors are trivial; passing bool by reference blocks hoisting and loop-specialization; reinterpret_cast of bytes is undefined and memcpy sometimes gets eliminated and sometimes not, and std::variant::visit can emit surprisingly heavy indirection. Slides and code live on the CppCon2018 GitHub link in the description.
AI-written summary · about
chapters (13)
- 0:00Introduction and motivation
- 1:26What the talk covers
- 10:30Compiler constraints and basics
- 17:42Inlining and its importance
- 23:03Const propagation explained
- 28:06Passing by reference pitfalls
- 34:12Branches and optional usage
- 37:05Forcing compiler optimizations
- 39:36Sorting and function pointers
- 41:19Reading bytes to structs safely
- 47:02Variant and visitor patterns
- 51:01Compiler limitations and advice
- 52:10Q&A session
related talks
52mUnderstanding Compiler Optimization
35mInlining: bright victories and hidden defeats
28mCode optimization tips and tricks
50mC++ Costless Abstractions: the compiler view
48mOptView2 - Helping the Compiler Generate Better Code
34mWhat happens to your code when you don't look?
58mOptimization Remarks - "Remarks Helping the Compiler Generate Better Code"
34mCode Size Compiler Optimizations and Techniques for Embedded Systems
