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

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 3 04:06:02 PDT 2016


On 11/3/16 5:20 AM, Andrei Alexandrescu wrote:
> On 11/02/2016 11:43 PM, 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.
>> With metaprogramming-heavy code, it's easy to run into some optimizer
>> performance corner cases, however this may make an impact regardless.
>>
>
> That's interesting. cc Dmitry, perhaps adding that to ctRegex would be
> helpful. -- Andrei
>

For ctRegex it's hardly applicable as it reuses the same code for 
run-time and compile-time version.

---
Dmitry Olshansky


More information about the Digitalmars-d mailing list