Dynamic Closure + Lazy Arguments = Performance Killer?

Jason House jason.james.house at gmail.com
Fri Oct 24 18:08:54 PDT 2008


bearophile wrote:

> Jason House:
> 
>> 34% of the execution time is used by std.random.uniform.
> 
> Kiss of Tango is much faster, and there's a much faster still (but good
> still) rnd generator around...
> 
> 
>> Can anyone verify that this is the case?
> 
> Can you show us a working minimal code I/we can test?
> 
> -------------------
> 
> Frank Benoit:
> 
>>The D2 full closure "feature" effectively removes it and makes D2 less
>>attractive IMHO.<
> 
> The first simple solution is to add the possibility of adding "scope" to
> closures to not use the heap (but I don't know how to do that in every
> situation, and it makes the already long syntax of lambdas even longer).
> 
> But the probably best way for D to become more functional (and normal
> functional programming is often full of functions that move everywhere,
> often they are closures, but only virtually) is to grow some more
> optimizing capabilities, so closures aren't a problem anymore. There are
> many ways to perform such optimizations (but in a language mostly based on
> side effects it's less easy).
> 
> Bye,
> bearophile

The following spends 90% of its time in _d_alloc_memory
void bar(lazy int i){}
void foo(int i){ bar(i); }
void main(){ foreach(int i; 1..1000000) foo(i); }

Compiling with -O -release reduces it to 88% :)



More information about the Digitalmars-d mailing list