July 26, 2012
On 26/07/12 15:42, Andrei Alexandrescu wrote:
>> If you can advise some flag combinations (for D and C++) you'd like to
>> see tested, I'll happily do them.
>
> The classic to ones are: (a) no flags at all, (b) -O -release -inline, (c) -O
> -release -inline -noboundscheck.

Here's a little table of DMD to GDC comparisons for the Dregs codebase:

                              ----------DMD----------    ----------GDC----------
compiler flags                compile time    runtime    compile time    runtime
-O -release -inline               0.43s           52s        1.51s           25s
-O -release                       0.35s           47s        1.50s           25s
-O -noboundscheck                 0.35s           56s        1.66s           25s
-O -inline                        0.47s        1m  5s        1.94s           45s
-O                                0.36s        1m  5s        1.98s           45s
-release -inline                  0.31s        1m  3s        0.63s        1m  3s
-release                          0.29s        1m  3s        0.63s        1m  3s
-inline                           0.32s        1m 24s        0.70s        1m 26s
-noboundscheck                    0.29s        1m 10s        0.666s       1m  9s
[none]                            0.29s        1m 24s        0.72s        1m 26s
-debug                            0.30s        1m 24s        0.70s        1m 26s
-unittest                         0.42s        1m 25s        0.75s        1m 26s
-debug -unittest                  0.42s        1m 25s        0.78s        1m 26s

July 26, 2012
On 07/26/2012 02:28 AM, Jacob Carlborg wrote:
> On 2012-07-25 23:56, Jonathan M Davis wrote:

> Incremental builds don't have to mean "pass a single file to the
> compiler". You can start by passing all the files at once to the
> compiler and then later you just pass all the files that have changed,
> at once.

GNU make has the special $? prerequisite that may help with the above: "The names of all the prerequisites that are newer than the target, with spaces between them. "

  http://www.gnu.org/software/make/manual/make.html#index-g_t_0024_003f-944

Ali

July 26, 2012
On 2012-07-26 19:54, Ali Çehreli wrote:

> GNU make has the special $? prerequisite that may help with the above:
> "The names of all the prerequisites that are newer than the target, with
> spaces between them. "
>
>
> http://www.gnu.org/software/make/manual/make.html#index-g_t_0024_003f-944
>
> Ali
>

I'm trying to avoid "make" as much as possible.

-- 
/Jacob Carlborg
July 26, 2012
On Thursday, July 26, 2012 18:00:21 Joseph Rushton Wakeling wrote:
> On 26/07/12 15:42, Andrei Alexandrescu wrote:
> >> If you can advise some flag combinations (for D and C++) you'd like to see tested, I'll happily do them.
> > 
> > The classic to ones are: (a) no flags at all, (b) -O -release -inline, (c)
> > -O -release -inline -noboundscheck.
> 
> Here's a little table of DMD to GDC comparisons for the Dregs codebase:
> 
>                      ----------DMD----------    ----------GDC----------
> compiler flags       compile time    runtime    compile time    runtime
> -O -release -inline      0.43s           52s        1.51s           25s
> -O -release              0.35s           47s        1.50s           25s
> -O -noboundscheck        0.35s           56s        1.66s           25s
> -O -inline               0.47s        1m  5s        1.94s           45s
> -O                       0.36s        1m  5s        1.98s           45s
> -release -inline         0.31s        1m  3s        0.63s        1m  3s
> -release                 0.29s        1m  3s        0.63s        1m  3s
> -inline                  0.32s        1m 24s        0.70s        1m 26s
> -noboundscheck           0.29s        1m 10s        0.666s       1m  9s
> [none]                   0.29s        1m 24s        0.72s        1m 26s
> -debug                   0.30s        1m 24s        0.70s        1m 26s
> -unittest                0.42s        1m 25s        0.75s        1m 26s
> -debug -unittest         0.42s        1m 25s        0.78s        1m 26s

Clearly -O is where the big runtime speed difference is at between dmd and gdc, which _is_ a bit obvious, but I'm surprised that -inline had no differences, since dmd is generally accused at being poor at inlining. That probably just indicates that it's a frontend issue (which I suppose makes sense when I think about it).

I guess that the way to go if you want to maxize both your efficiency and the code's efficiency is to do most of the coding with dmd but generate the final program with gdc (though obviously building and testing with both the whole way is probably necessary to ensure stability; still much of that could be automated and not affect programmer efficiency).

- Jonathan M Davis
July 26, 2012
On Thursday, 26 July 2012 at 18:59:14 UTC, Jonathan M Davis wrote:
> Clearly -O is where the big runtime speed difference is at between dmd and gdc,
> which _is_ a bit obvious, but I'm surprised that -inline had no differences,
> since dmd is generally accused at being poor at inlining. That probably just
> indicates that it's a frontend issue (which I suppose makes sense when I think
> about it).

GDC probably performs inlining by default on -O2/-O3, just like LDC does.

Also note that for the -release case (any performance measurements without it are most probably not worth it due to all the extra _d_invariant, etc. calls), -inline seems to increase the runtime of the DMD-produced executable by 10%. For inlining, you inevitably have to rely on heuristics, and there will always be cases where it slows down execution (worst case: the slight improvement in code size causes cache thrashing in a hot path), but 10% in a fairly standard application seems to be quite a lot.

David
July 26, 2012
On Thursday, 26 July 2012 at 18:59:14 UTC, Jonathan M Davis wrote:
> […] That probably just
> indicates that it's a frontend issue (which I suppose makes sense when I think
> about it).

Oh, and I don't know what exactly you are referring to here, but any difference between DMD and GDC is likely not a frontend issue, as GDC uses the DMD frontend, with only minor modifications.

David
July 26, 2012
On Thursday, July 26, 2012 21:29:57 David Nadlinger wrote:
> On Thursday, 26 July 2012 at 18:59:14 UTC, Jonathan M Davis wrote:
> > […] That probably just
> > indicates that it's a frontend issue (which I suppose makes
> > sense when I think
> > about it).
> 
> Oh, and I don't know what exactly you are referring to here, but any difference between DMD and GDC is likely not a frontend issue, as GDC uses the DMD frontend, with only minor modifications.

That was my point. -inline seems to be pretty much identical between the two compilers, and if the inlining is done in the frontend, then that makes sense. Thinking on it, it makes sense to me that it would be in the frontend, but I don't know where it actually is.

- Jonathan M Davis
July 26, 2012
On Thursday, 26 July 2012 at 19:36:51 UTC, Jonathan M Davis wrote:
> That was my point. -inline seems to be pretty much identical between the two
> compilers, and if the inlining is done in the frontend, then that makes sense.
> Thinking on it, it makes sense to me that it would be in the frontend, but I
> don't know where it actually is.

Ah, okay, I see what you meant. But no, as far as I'm aware, GDC doesn't use DMD's inliner, but rather relies on the GCC one. LDC does the same, we entirely disable DMD's inlining code, it turned out to just be not worth it.

David
July 26, 2012
On Thu, 26 Jul 2012 10:54:07 -0700
Ali Çehreli <acehreli@yahoo.com> wrote:

> On 07/26/2012 02:28 AM, Jacob Carlborg wrote:
>  > On 2012-07-25 23:56, Jonathan M Davis wrote:
> 
>  > Incremental builds don't have to mean "pass a single file to the
>  > compiler". You can start by passing all the files at once to the
>  > compiler and then later you just pass all the files that have
>  > changed, at once.
> 
> GNU make has the special $? prerequisite that may help with the above: "The names of all the prerequisites that are newer than the target, with spaces between them. "
> 
>    http://www.gnu.org/software/make/manual/make.html#index-g_t_0024_003f-944
> 

So in other words, it'll completely crap out when a path contains
spaces? (What is this, 1994?)

July 26, 2012
On 26/07/12 20:27, David Nadlinger wrote:
> GDC probably performs inlining by default on -O2/-O3, just like LDC does.

I was surprised that using -inline alone (without any optimization option) doesn't produce any meaningful improvement.  It cuts maybe 1s off the DMD-compiled runtime, but it's not clear to me that actually corresponds to a reliable difference.  Perhaps GDC just ignores the -inline flag ... ?

I suppose it's possible that this is code that does not respond well to inlining, although I'd have thought the obvious optimization would be to inline many of the object methods that are only called internally and that are called in a tight loop:

            do {
                  userDivergence(ratings);
                  userReputation(ratings);

                  reputationObjectOld_[] = reputationObject_[];
                  objectReputation(ratings);
                  diff = 0;
                  foreach(size_t o, Reputation rep; reputationObject_) {
                        auto aux = rep - reputationObjectOld_[o];
                        diff += aux*aux;
                  }
                  ++iterations;
            } while (diff > convergence_);

I might tweak it manually so that userDivergence(), userReputation() and objectReputation() are inline, and see if it makes any difference.
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home