D is supposed to compile fast.
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Nov 23 18:13:24 UTC 2018
On Fri, Nov 23, 2018 at 05:37:46PM +0000, Adam D. Ruppe via Digitalmars-d-learn wrote:
> On Friday, 23 November 2018 at 17:21:46 UTC, H. S. Teoh wrote:
> > Are you using template-heavy Phobos functions?
>
> Merely importing a Phobos module is liable to cost you a quarter
> second or more of compile time.
Yes, I'm aware of that. It used to be the case that the mere importing
of std.format would add 2-3 seconds to your compile time, but I think
the worst of it has been fixed. It's still not cheap to use std.format,
but it's improved from what it used to be.
> I just got my gui lib (22,000 lines of raw source, dscanner -sloc
> reports 12,000) compiling in 0.2s on Linux, down from 1.0s, by
> removing ALL the phobos imports. It is 0.6s on Windows, probably
> because it imports so many of the Windows headers.
Yeah, I find that avoiding certain Phobos modules like std.format or
std.regex really does help a lot in improving compile times.
> I like to say C style and Java style code compiles really fast... but
> you wanna beware of imports of the standard library, since it brings
> in a LOT of code, some of which is really slow to run (parts of it are
> slower than others, like std.algorithm is actually pretty fast to
> compile+use, but std.regex is brutally slow)
Well yes, std.algorithm is practically all templates, and relatively
small ones (except for bears like cartesianProduct, no thanks to yours
truly :-/), so even though std.algorithm.* is pretty big in terms of
LOC, you only pay for what you use. But std.regex has basically
template-driven internals, and IIRC has static tables that are generated
by templates and/or CTFE, so it can really slow the compiler down.
The other big offender is std.uni, which imports some pretty large
templated tables that adds a few seconds to compile times.
All in all, though, the fact that we're complaining about extra seconds
in compilation times still does show just how fast D compilation can be.
In the old days, compiling large C++ codebases usually means 30 mins to
2 hours, and a few extra seconds won't even be noticed. I haven't
checked C++ compile times recently, though -- things may have improved
since I last seriously used C++.
T
--
IBM = I'll Buy Microsoft!
More information about the Digitalmars-d-learn
mailing list