On Thursday, 3 March 2016 at 11:40:29 UTC, John Colvin wrote:
On Thursday, 3 March 2016 at 02:03:01 UTC, maik klein wrote:
Consider the following code

void main()
{
    import std.stdio;
    import std.range: iota, join;
    import std.algorithm.iteration: map;
    import std.conv: to;
    import std.meta: aliasSeqOf, staticMap, AliasSeq;
enum types = "AliasSeq!(" ~ iota(0,10000).map!(i => to!string(i)).join(",") ~ ")";
    alias t = AliasSeq! (mixin(types));
    //alias t1 = aliasSeqOf!(iota(0, 10000));
}

't' compiles on my machine in ~3.5 seconds while 't1' needs ~1 minute to compile. It seems that mixins are just way more performant than template instantiations. Any ideas why? What causes the slowdown and what can I improve?

What happens if you add a few extra branches to std.meta.aliasSeqOf, e.g. https://github.com/D-Programming-Language/phobos/commit/5d2cdf103bd697b8ff1a939c204dd2ed0eec0b59

Only a linear improvement but maybe worth a try?

I have tried the same thing in general and stuff like this is always a huge improvement.

In this case it goes down from ~60 seconds to ~3.8 seconds. I have done the same thing with my compile time map function, which gave me a drastic improvement.

I think recursion is just really bad in general for compile time stuff, for example your version

alias t1 = aliasSeqOf!(iota(0, 10000));

compiles in 3.8 seconds and uses roughly 600mb of ram while

alias t1 = aliasSeqOf!(iota(0, 20000));

compiles in 10.2 seconds and uses 1.9gb ram.

The mixin version is always the fastest but it also consumes way more memory and explodes before 20k elements


Reply via email to