Jai compiles 80,000 lines of code in under a second

Adam D. Ruppe destructionator at gmail.com
Fri Sep 21 00:47:27 UTC 2018


On Thursday, 20 September 2018 at 23:13:38 UTC, aliak wrote:
> he can now compile an 80,000 line game in about 1.5 seconds on 
> a laptop

D can compile similar amounts of code in half the time.

For example, the entire D1 runtime and standard library can be 
built (compiled and linked!) in 0.6 seconds on my computer, and 
it is about 82,000 lines of code.

A good chunk of my gui libs in D: terminal.d, simpledisplay.d, 
minigui.d, nanovega.d, color.d, and dom.d for good measure, can 
be compiled in 1 second on my computer. That is ~49,000 lines of 
code. Back when I didn't use phobos in them, it compiled in about 
1/3 that time - see, that's the hidden cost of builds: you 
frequently need to compile parts of the standard library too. In 
C++, this is caused by #include (sort of, C++ mitigates it in 
practice though). In D, it is templates. Any templates you use 
from the stdlib will be compiled and instantiated too - and this 
is slow.


Of course, D can also take ages to compile one line of code. It 
all depends on that that line is doing... ctfe and templates are 
slow. C or Java style code compiling in D is very fast.

> Have compile times gotten worse in D over the years or better 
> or just stayed the same?

Well, if you still compile D code written in and older style - 
like my example of the D1 phobos - it still builds exceedingly 
quickly. Just that older style is less common  nowadays - using 
Phobos function is frequently the slowest part of compiling my 
code with D2, whereas D1 it was all written C style, and would 
build in the blink of an eye.

So dmd hasn't gotten much slower, but the typical D style has 
moved toward using more of the slower parts of the compiler 
instead of the faster parts.


More information about the Digitalmars-d mailing list