On 9/20/2013 8:54 AM, Joseph Rushton Wakeling wrote:
On 20/09/13 17:28, Andrei Alexandrescu wrote:
Why would there be a performance loss?
Depends on the particular case, but my experience is that _in practice_ stuff
based around range interfaces can often be slower than raw iteration.
I don't think anyone's saying a performance loss is inevitable or unavoidable,
but there currently is one.
I know that, at least with dmd's back end, it's because the optimizer was built
around the kinds of things that C++ programmers tend to write. The D
range/algorithm generates unusual code (for the back end) that the back end
doesn't optimize for.
For example, ranges tend to lump several variables together and call them a
'struct'. The back end is not tuned to deal with structs as an aggregate of
discreet 'variables', meaning that such variables don't get assigned to
registers. Structs are treated as a lump.
This is not a fundamental performance problem with D.
The back end needs to be improved to "dis-aggregate" structs back into discreet
variables.