CTFE Memory Hogging Workaround?

Jonathan M Davis jmdavisProg at gmx.com
Thu Nov 22 18:03:42 PST 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


More information about the Digitalmars-d-learn mailing list