Speed up compilation of CTFE-heavy programs with this One Weird Trick!

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 3 05:19:09 PDT 2016


Am 03.11.2016 um 04:43 schrieb Vladimir Panteleev:
> For each function that is only called during compilation (e.g. for code
> generation), at the top add:
>
>     if (!__ctfe)
>         return;
>
> That's it. For one project, this brought compilation time (with
> optimizations) from over an hour down to seconds!
>
> As it turns out, DMD will codegen all functions, even templated ones
> when they're instantiated, whether they're called by something or not.
> With metaprogramming-heavy code, it's easy to run into some optimizer
> performance corner cases, however this may make an impact regardless.
>

Does "if (!_ctfe) assert(false);" work, too? That would also protect 
against accidential mistakes.


More information about the Digitalmars-d mailing list