Thread overview
CTFE Memory Hogging Workaround?
Nov 22, 2012
Maxime Chevalier
Nov 23, 2012
Timon Gehr
Nov 23, 2012
Jonathan M Davis
November 22, 2012
One of the reasons I chose to use D for my project is that I was very excited about the prospect of using CTFE in mixin code. Unfortunately, there seems to be one (or several?) bugs causing CTFE to be very slow and to hog a huge amount of memory (multiple gigs of RAM and swap). I use the latest dmd and my mixin code uses an Appender!string object to produce a long string of D code containing multiple functions (~1500 lines).

Is there some known fix for this? I need this to work now. Otherwise, I'm going to have to rewrite my CTFE/mixin code in Python or something, which would be a shame, and a waste of time on my part. This is not the first compiler bug I run into, and I'm starting to regret not implementing my project in C++ instead.
November 23, 2012
On 11/22/2012 11:33 PM, Maxime Chevalier wrote:
> One of the reasons I chose to use D for my project is that I was very
> excited about the prospect of using CTFE in mixin code. Unfortunately,
> there seems to be one (or several?) bugs causing CTFE to be very slow
> and to hog a huge amount of memory (multiple gigs of RAM and swap). I
> use the latest dmd and my mixin code uses an Appender!string object to
> produce a long string of D code containing multiple functions (~1500
> lines).
>
> Is there some known fix for this? ...

Simple code generation should work fine, even given the current implementation quality. You need to determine what part causes it to be slow. Comment out some of the code and do measurements. Also try using plain strings instead of appender.

I cannot give any more support given the limited information.
November 23, 2012
On Friday, November 23, 2012 02:04:44 Timon Gehr wrote:
> On 11/22/2012 11:33 PM, Maxime Chevalier wrote:
> > One of the reasons I chose to use D for my project is that I was very excited about the prospect of using CTFE in mixin code. Unfortunately, there seems to be one (or several?) bugs causing CTFE to be very slow and to hog a huge amount of memory (multiple gigs of RAM and swap). I use the latest dmd and my mixin code uses an Appender!string object to produce a long string of D code containing multiple functions (~1500 lines).
> > 
> > Is there some known fix for this? ...
> 
> Simple code generation should work fine, even given the current implementation quality. You need to determine what part causes it to be slow. Comment out some of the code and do measurements. Also try using plain strings instead of appender.
> 
> I cannot give any more support given the limited information.

Other tips are to generally use a smaller number of larger mixins rather than lots of small ones, and splitting code up across modules and compiling them separately can help if you have a lot of mixed in code.

- Jonathan M Davis