[SO] question on trivial function inlining

bearophile bearophileHUGS at lycos.com
Fri Jul 10 16:04:42 PDT 2009


Benjamin Shropshire:
> Anyone care to add more details?
> http://stackoverflow.com/questions/1109995/do-getters-and-setters-impact-performance-in-c-d-java/1110324#1110324

I think DMD is currently unable to de-virtualize virtual getters and setters. Virtual calls are a bit slower by itself, but they also don't allow inlining, so successive standard optimizations can't be done. So if such accesses to the attribute is a virtual call and this happens in a "hot" part of the code, then it may slow down your code significantly. (if it happens in non-hot parts of the code it has usually no effects. That's why Java Hot Spot doesn't need optimize all your code to produce a very fast program anyway).

I have encouraged Frits van Bommel to improve the devirtualization capabilities of LDC:
http://www.dsource.org/projects/ldc/changeset/1506%3A76936858d1c6
Now LDC is able to do that in few very simple situations, but most times the situation is unchanged compared to DMD. Eventually LLVM will improve, so this situation can improve by itself. But the front-end too may do something about this.

Some documentation about this topic, something older:
http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=B26C4304DB1DA05ECBD67CA7D9313511?doi=10.1.1.7.7766&rep=rep1&type=pdf

Some more modern:
http://ols.fedoraproject.org/GCC/Reprints-2006/namolaru-reprint.pdf

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list