Splitting std.algorithm

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 22 11:33:57 PST 2015


On Thu, Jan 22, 2015 at 11:29:16AM -0800, Jonathan M Davis via Digitalmars-d wrote:
> On Thursday, January 22, 2015 19:12:55 Dicebot via Digitalmars-d wrote:
> > DMD FE memory issues are almost fully because of template instance
> > explosions and CTFE. Micro-optimising structure layouts is a bad way
> > to fix it.
> 
> I forget what the numbers were, but IIRC, when Don looked at that a
> while back, he found that templates like isForwardRange were being
> instantiated millions of times as part of the unit tests. And maybe
> the numbers weren't quite that high, but they were _high_.
> std.datetime used to have similar problems when I used assertPred for
> its unit tests, which was a very handy templated function for making
> unit tests more informative, but it was a template, and it was used a
> lot in the tests, so it wasn't cheap, and once it was removed, the
> memory consumption and time to compile definitely went down.
> 
> It would be a huge win if we could figure out how to avoid having all
> of those templates instantiated that many times.
[...]

One idea would be to detect if a template doesn't actually generate any
code (doesn't contain any functions or variable declarations in the
outermost scope), and switch to a CTFE-style evaluation of the template
without actually storing any of its instantiations.

But I've no idea whether such an idea is feasible in the current
compiler implementation, or whether it will actually help anything. DMD
not reclaiming *any* memory whatsoever in the name of speed is the
bugbear that hinders improvement in this area.


T

-- 
"The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." -- Bertrand Russell. "How come he didn't put 'I think' at the end of it?" -- Anonymous


More information about the Digitalmars-d mailing list