Why is D slower than LuaJIT?

bearophile bearophileHUGS at lycos.com
Wed Dec 22 16:43:02 PST 2010


Andreas Mayer:

> To see what performance advantage D would give me over using a scripting language, I made a small benchmark. It consists of this code:

I have done (and I am doing) many benchmarks with D, and I too have seen similar results. I have discussed this topic two times in past, this was one time:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=110419
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=110420

For Floating-point-heavy code Lua-JIT is often faster than D compiled with DMD. I have found that on the SciMark2 benchmark too Lua-JIT is faster than D code compiled with DMD. On the other hand if I use LDC I am often able to beat LuaJIT 2.0.0-beta3 (we are now at beta5) (if the D code doesn't ask for too much inlining).

The Lua-JIT is written by a very smart person, maybe a kind of genius that has recently given ideas to designers of V8 and Firefox JS Engine. The LuaJIT uses very well SSE registers and being a JIT it has more runtime information about the code, so it is able to optimize it better. It unrolls dynamically, inlines dynamic things, etc. DMD doesn't perform enough optimizations. Keep in mind that the main purpose of DMD is now to finish implementing D (and sometimes to find what to implement! Because there are some unfinished corners in D design). Performance tuning is mostly for later.

-------------------------

Walter Bright:

>If it's not clear, I'd like to emphasize that these are compiler issues, not D language issues.<

Surely Lua looks like a far worse language regarding optimization opportunities. But people around here (like you) must start to realize that JIT compilation is not what it used to be. Today the JIT compilation done by the JavaVM is able to perform de-virtualization, dynamic loop unrolling, inlining across "compilation units", and some other optimizations that despite are "not language issues" are not done or not done enough by static compilers like LDC, GCC, DMD. The result is that SciMark2 benchmark is about as fast in Java and C, and for some sub-benchmarks it is faster :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list