4 ms·
> It's not the complication that bugs me: it's the runtime inefficiency! Used carelessly, C++ templates produce massive code bloat from repetitive instantiation
by throwaway613834 9y ago
> It's not the complication that bugs me: it's the runtime inefficiency! Used carelessly, C++ templates produce massive code bloat from repetitive instantiations.
You mean you actually experience slowness clearly attributable to instruction cache misses? I don't know if I've ever had that. What bugs me is the compile-time inefficiency. A lot of times the same method gets regenerated for every time in the enclosing class even though most if not all of it could just as well be in the base class without the template parameter, to only get instantiated once.
- AstralStorm 9y agoThere are tricks to avoid it if you really want to. Precompiled headers, force instantiating templates you need with LTO enabled and caching. Merging source files in the build system (possible thanks to ODR). Calling the compiler with many source files at once to use compiler cache. The remaining inefficiency is supposed to go away with the upcoming module system.
- kbwt 9y ago> The remaining inefficiency is supposed to go away with the upcoming module system. That's really not the main goal of the module system. It's more about code hygiene, no matter how much people are hoping it will completely solve the issue with compile times.
- quotemstr 9y agoThe page faults are usually worse than the icache misses. Code is not free.