www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CTFE Memory Hogging Workaround?

reply "Maxime Chevalier" <maximechevalierb gmail.com> writes:
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.
Nov 22 2012
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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.
Nov 22 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Nov 22 2012