Dynamic Closure + Lazy Arguments = Performance Killer?

Jason House jason.james.house at gmail.com
Sat Oct 25 01:24:47 PDT 2008


bearophile Wrote:

> Jason House:
> > 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% :)
> 
> I see. So I presume it becomes quite difficult for D2 to compute up to the 25th term of this sequence (the D code is in the middle of the page) (it takes just few seconds to run on D1):
> http://en.wikipedia.org/wiki/Man_or_boy_test
> 
> What syntax can we use to avoid heap allocation? Few ideas:
> 
> void bar(lazy int i){} // like D1
> void bar(scope lazy int i){} // like D1
> void bar(closure int i){} // like current D2
> 
> Bye,
> bearophile

I would assume a fix would be to add scope to input delegates and to require some kind of declaration on the caller's side when the compiler can't prove safety. It's best for ambiguous cases to be a warning (error). It also makes the code easier for readers to follow.



More information about the Digitalmars-d mailing list