Major performance problem with std.array.front()

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Mar 10 19:56:22 PDT 2014


On 3/10/14, 7:07 PM, Steven Schveighoffer wrote:
> On Mon, 10 Mar 2014 19:59:07 -0400, Walter Bright
> <newshound2 at digitalmars.com> wrote:
>
>> On 3/10/2014 6:47 AM, Dicebot wrote:
>>> (array literals that allocate, I will never forgive that).
>>
>> It was done that way simply to get it up and running quickly. Having
>> them not allocate is an optimization, it doesn't change the nature.
>
> I think you forget about this:
>
> foo(int v, int w)
> {
>     auto x = [v, w];
> }
>
> Which cannot pre-allocate.

It actually can, seeing as x is a dead assignment :o).

> That said, I would not mind if this code broke and you had to use
> array(v, w) instead, for the sake of avoiding unnecessary allocations.

Fixing that:

int[] foo(int v, int w) { return [v, w]; }

This one would allocate. But analyses of varying complexity may 
eliminate a variety of allocation patterns.


Andrei




More information about the Digitalmars-d mailing list