Mutual optimization of tail recursion does not work in D

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 31 06:50:16 PDT 2015


On Tue, Mar 31, 2015 at 11:57:49AM +0000, w0rp via Digitalmars-d-learn wrote:
> Mutual tail call optimisation doesn't work in C++ either.
> 
> Because it's not a language feature in C++ or D. It is not required by
> the standards of either language. It's an optimisation which compilers
> apply. I am guessing you are using DMD, which might not offer the best
> optimisations for runtime code, but has other benefits.
> 
> You might want to try GDC or LDC. I am not certain if they implement
> tail call optimisations, but they might do, and it seems like a good
> optimisation to have. I'm sure this has been discussed before.

In general, if you care about performance, I highly recommend using gdc
or ldc instead of dmd. Dmd's backend is not as good at optimization as
gdc or ldc. For compute-intensive programs, I find that gdc -O3
consistently produces code that performs about 20% (sometimes up to 50%)
better than dmd-produced code, even with all dmd optimization flags
turned on.


T

-- 
MAS = Mana Ada Sistem?


More information about the Digitalmars-d-learn mailing list