Optimizing compilation times with Templates
summary
Facebook’s Thrift RPC code generates huge per-field serializers so template instantiation dominates build time; measuring with -ftime-report and the Templight tracer shows one template taking 60s of a 350s front end (≈20%) and overall slowest unit dropping from ~800s to ~400s (~50%). Fix replaces repeated generated code with a generic templated library using type-tagging (swap SFINAE enable_if for constant-time tags), reducing instantiation time by an order of magnitude and improving runtime serialization ~5%.
AI-written summary · about
chapters (12)
- 0:00Introduction and motivation
- 1:03Template compilation myths
- 3:10How template instantiation works
- 7:25Measuring compile times
- 11:22Thrift framework overview
- 12:24Identifying template bottlenecks
- 15:20Optimization hypothesis
- 16:24First optimization attempt
- 17:52Type tagging solution
- 19:20Results and improvements
- 21:36Why optimize compilation times
- 22:44Q&A session
related talks
47mReducing Template Compilation Overhead, Using C++11, 14, 17, and 20.
05mHow To Profile Compilation Duration?
54m“The Power of Reflection with Facebook's Thrift"
53mWhy Is My C++ Build So Slow? Compilation Profiling and Visualization
01h 30mRethinking the Way We Do Templates in C++
53mReducing C++ Compilation Times Through Good Design
50mC++ Costless Abstractions: the compiler view
01h 01mRethinking the Way We Do Templates in C++
