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

Era Scarecrow via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 3 01:56:53 PDT 2016


On Thursday, 3 November 2016 at 03:43:06 UTC, Vladimir Panteleev 
wrote:
> 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.

  Sounds like an issue. Although, I almost think a @noctfe tag 
which would refuse to compile/use code during CTFE, or in effect 
add that line at the beginning to functions invisibly.

  Obviously having functions only voluntarily used for CTFE would 
be a pain. having a section Opt Out after a certain point seems 
more useful, and would require far less work for the programmers.


More information about the Digitalmars-d mailing list