www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Optimization of simple properties

reply Jason House <jason.james.house gmail.com> writes:
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?
Oct 11 2008
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
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
Oct 11 2008
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
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?
Oct 11 2008