D is supposed to compile fast.

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Nov 23 17:21:46 UTC 2018


On Fri, Nov 23, 2018 at 08:57:57AM +0000, Chris Katko via Digitalmars-d-learn wrote:
> Any time I see people mention the benefits of D, I see "compile times"
> "compile times" "compile times" over and over.

D is extremely fast at compilation ... of C-like code. :-D

Anything involving heavy use of templates and/or CTFE will quickly slow
things down, sometimes by a lot.


> 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!

Are you using template-heavy Phobos functions?  Some parts of Phobos are
known to be extremely slow, e.g., std.format (which is indirectly
imported by std.stdio), due to the sheer amount of templates it uses.


[...]
> I keep putting stuff into new files, but it feels like it's compiling
> everything from scratch / not getting faster the way C++ does.

Are you still compiling everything in one command, or separately
compiling?  There's not much point (as far as compile times are
concerned) in splitting up into new files if you're still compiling
everything each time.


> 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.)

Yeah, std.regex is known to be pretty nasty in terms of compile times /
memory usage, because its internals uses a LOT of templates.  There have
been efforts to fix / improve this, but I haven't kept up with the
developments, so I'm not sure where things are at now.

One caveat about std.regex, though: you may actually want to use runtime
regexen instead of ctRegex, in spite of the supposed performance
improvements; I recall reading somewhere that ctRegex actually isn't as
fast as you might think, yet it comes at a HUGE compile-time cost (and I
do mean HUGE...  it can significantly increase compile times for only
marginal or sometimes even negative runtime performance -- because of
template bloat).  I've stopped using ctRegex altogether and just been
initializing regexen with `static this()` instead.  Or sometimes even
just pure runtime regexen, because the cost of initializing once is
insignificant compared to subsequent repeated usage.


T

-- 
Too many people have open minds but closed eyes.


More information about the Digitalmars-d-learn mailing list