Array!T and find are slow

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 14 16:50:33 PDT 2014


On Wednesday, 14 May 2014 at 22:32:01 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:
> Yeah, much as Andrei would hate to hear it (enforce was his 
> idea, and he quite
> likes the idiom), the fact that lazy is so inefficient makes it 
> so that it's
> arguably bad practice to use it in high performance code. We 
> really need to
> find a way to make it so that lazy is optimized properly so 
> that we _can_
> safely use enforce, but for now, it's not a good idea unless 
> the code that
> you're working on can afford the performance hit.
>
> Honestly, in general, I'd avoid most anything which uses lazy 
> (e.g. that's why
> I'd use explict try-catch blocks rather than use
> std.exception.assumeWontThrow - like enforce, it's a nice idea, 
> but it's too
> expensive at this point).
>
> - Jonathan M Davis

On the topic of lazy, why *is* it so slow, exactly? I thought it 
was just shorthand for taking a function that evaluates the 
expression, and wrapping said expression in that function at the 
call site. That is, I thought that:

int doSomething(lazy int n)
{
     return n();
}

Was more or less equivalent to:

int doSomething(int function(int) n)
{
     return n();
}


More information about the Digitalmars-d-learn mailing list