D is supposed to compile fast.

Stefan Koch uplink.coder at googlemail.com
Mon Nov 26 21:15:39 UTC 2018


On Friday, 23 November 2018 at 08:57:57 UTC, Chris Katko wrote:
> Any time I see people mention the benefits of D, I see "compile 
> times" "compile times" "compile times" over and over.
>
> I'm using very modest amounts of templates, for a fairly small 
> sized program (very early work toward a game), and I'm hitting 
> ~15 seconds compile time in LDC and ~7 seconds in DMD. And I'm 
> not even compiling with optimizations!
>
> ldc2 -w -ofextra  extra.d molto.d helper.d editor.d common.d 
> map.d object_t.d animation.d ini.d  -L-L. $@    -gc -d-debug=3  
> -de -fdmd-trace-functions
>
> dmd -w -ofextra extra.d molto.d helper.d editor.d common.d 
> map.d object_t.d animation.d ini.d -profile=gc  -profile  -g 
> -debug -color -L-L.
>
> I keep putting stuff into new files, but it feels like it's 
> compiling everything from scratch / not getting faster the way 
> C++ does.
>
> And I'm not even bringing up the 800MB of RAM required because 
> I dared to import std.regex. (On a laptop with 2 GB of RAM. 
> RIP. If I dare to have tabs open, the compile time goes into 
> the minutes thanks to swapping.)

I've profiled your example, unsurprisingly allmost all of the 
compiletime is eaten by regex, which is executed at compile-time.
Most of the time there is actually taken by the 
template-instantiation and the templates which are involved in 
building the IR and such.

newCTFE helps out a little, but for this to be fast, std.regex 
would have to be rewritten with CTFE in mind.

Maybe you can generate a finite automaton for your regex offline 
using some other engine like which supports D or C.

That alone should cut a few seconds of your compile-times and 
prevent out-of-memory errors,

I hope this helps.

Cheers,

Stefan


More information about the Digitalmars-d-learn mailing list