How to reduce compile times?

grauzone none at
Sat Mar 21 07:44:41 PDT 2009

I'm using dsss (with dmd under Linux) to compile my project, and 
build/compile times are reaching unacceptable highs.

What are some tips to speed up the build process?

For example, I could imagine that heavy use of templates and CTFE slows 
the compiler down. Maybe string mixins with CTFE on the module level are 
most expensive: here, the compiler has to do heavy weight semantic 
analysis every time a module is imported from another module (maybe even 
recursively). But I don't really know; it depends too much on how the 
compiler works internally.

Without some kind of "build profiler", I have no clue what is actually 
causing slow downs. It's like groping in the dark!

The only thing that comes near to this seems to be to insert a 
"pragma(msg, blabla)" at random points in your modules. Then you 
recompile the project and count how many times the message is outputted.

Actually, the whole issue seems to boil down to reducing module 
dependencies. But then again, your "main" module recursively depends 
from _all_ used modules in your project.

What I personally found useful in practice is to reduce the number of 
interdependent modules by separating them into interface and 
implementation modules, e.g. by using delegates or inheritance. Then you 
can "hide" the implementation from most modules by removing the static 
dependencies. But this only works in some cases, and is always inconvenient.

PS: another thing that possibly would bring a speed gain would be to 
make dsss compile the whole project in one run, instead of invoking a 
new dmd process for each source file. How do I need to change the 
rebuild configuration to achieve this?

More information about the Digitalmars-d-learn mailing list