Creeping Bloat in Phobos

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 15:09:46 PDT 2014


On Sat, Sep 27, 2014 at 09:59:17PM +0000, Peter Alexander via Digitalmars-d wrote:
> On Saturday, 27 September 2014 at 20:57:53 UTC, Walter Bright wrote:
> >From time to time, I take a break from bugs and enhancements and just
> >look at what some piece of code is actually doing. Sometimes, I'm
> >appalled.
> 
> Me too, and yes it can be appalling. It's pretty bad for even simple
> range chains, e.g.
> 
> import std.algorithm, std.stdio;
> int main(string[] args) {
>   return cast(int)args.map!("a.length").reduce!"a+b"();
> }

I vaguely recall somebody mentioning a while back that range-based code
is poorly optimized because compilers weren't designed to recognize
such patterns before. I wonder if there are ways for the compiler to
recognize range primitives and apply special optimizations to them.

I do find, though, that gdc -O3 generally tends to do a pretty good job
of reducing range-based code to near-minimal assembly. Sadly, dmd is
changing too fast for gdc releases to catch up with the latest and
greatest, so I haven't been using gdc very much recently. :-(


T

-- 
If Java had true garbage collection, most programs would delete
themselves upon execution. -- Robert Sewell


More information about the Digitalmars-d mailing list