August 26, 2008
Hey all,

I've got a sample that did take five minutes to compile and produced a 4MB executable, and now it's down to 2MB and just over a minute, but most of that (1.6MB) is just template code, and I'd like to reduce that further.

What are the typical suggestions for optimizing code that's heavy on templates? My major problem is build time, though executable size is also a concern. Runtime isn't important (the current code can run 10,000 times in a hundredth of a second on that hideously large example, and it shouldn't need to run very much at all).

For reference, the code is dconstructor, and the example is speed.d from the examples folder:
svn co http://svn.dsource.org/projects/dmocks/dconstructor/trunk
August 26, 2008
Christopher Wright:
> What are the typical suggestions for optimizing code that's heavy on templates? My major problem is build time, though executable size is also a concern.

You can try to replace many of the templates that compute stuff at compile time with compile-time functions (where they don't produce bugs). They are faster.

Bye,
bearophile