Templates are slow.

Lewis via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 8 12:17:42 PDT 2016


It's true that templates are inherently slow, and there isn't a 
ton we can do about that. However, almost every time I compile 
the project (hundreds of times per day), the overwhelming 
majority of the time, the same templates are being 
re-instantiated in exactly the same way. I can't help but wonder 
if there were some way to automatically cache templates 
instantiations between runs of dmd?

The heavytemplates.d workaround I've used kind of accomplishes 
this as a total hack job. However...

- It adds complexity to the build process
- It adds a small overhead of linking in an extra .lib (although 
this is dwarfed by the win from no longer rebuilding expensive 
templates every build)
- It means that when heavytemplates.d changes, my rebuild is 
significantly longer than before since I'm running dmd twice
- It means extra work to implement that we don't want every 
developer to do themselves

Am I crazy in wondering about caching template instantiations? I 
understand that an incremental build would kind of accomplish 
this goal, but that comes with its own set of problems. I can't 
help but think that there's some way to make dmd smarter about 
not redoing the exact same work build after build, when the 
templates and their instantiations only change very rarely.


More information about the Digitalmars-d mailing list