Thread overview
Optimization of simple properties
Oct 11, 2008
Jason House
Oct 11, 2008
bearophile
Oct 11, 2008
Denis Koroskin
October 11, 2008
Last night I changed my code to expose raw variables instead of offering properties.  The properties were simply returning a local variable.  I was surprised that such a simple and stupid change resulted in a 10% speed up for gdc-generated code.

Is this a bug unique to gdc (or the older gdc build that I have)? Is dmd smart enough to avoid this kind of problem?
October 11, 2008
Jason House:
> Is this a bug unique to gdc (or the older gdc build that I have)? Is dmd smart enough to avoid this kind of problem?

DMD is usually even less smart than GDC. But it's not a bug, it's a performance miss :-)
Current D compilers aren't much smart regarding optimizations. You will find that in several other things. With time (years) D compilers will become smarter. Java HotSpot is able to perform very complex optimizations, partial or total inlining of virtual methods, etc, etc. To perform some of those optimizations it may be useful to have lot of statistics regarding how the code is actually used, that's why virtual machines sometimes are faster than statically optimized code, even if you use "profile guided optimization" that the last Intel and GCC compilers have.

Bye,
bearophile
October 11, 2008
On Sat, 11 Oct 2008 22:59:45 +0400, Jason House <jason.james.house@gmail.com> wrote:

> Last night I changed my code to expose raw variables instead of offering
> properties.  The properties were simply returning a local variable.  I was
> surprised that such a simple and stupid change resulted in a 10% speed up
> for gdc-generated code.
>
> Is this a bug unique to gdc (or the older gdc build that I have)? Is dmd
> smart enough to avoid this kind of problem?

I assume you compile code with inline expansion enabled?