Thread overview
General performance tips
Jan 23, 2017
albert-j
Jan 23, 2017
Stefan Koch
Jan 23, 2017
albert-j
Jan 23, 2017
sarn
Jan 24, 2017
kinke
January 23, 2017
I have translated some simulation code from Java into D (a few classes, mostly manipulation of double arrays in small methods). D version runs 10-30% slower than Java (ldc2, dub release build). Profiling did not show any obvious bottlenecks. I am wondering whether I missed something, or such performance difference can be expected. I read on this forum that marking methods final and nothrow can help, but it didn't do much in my case. Is there anything else I should be looking for?
In general, something like a wiki page with performance tips would be very useful for D newcomers like me! :)
January 23, 2017
On Monday, 23 January 2017 at 11:11:21 UTC, albert-j wrote:
> I have translated some simulation code from Java into D (a few classes, mostly manipulation of double arrays in small methods). D version runs 10-30% slower than Java (ldc2, dub release build). Profiling did not show any obvious bottlenecks. I am wondering whether I missed something, or such performance difference can be expected. I read on this forum that marking methods final and nothrow can help, but it didn't do much in my case. Is there anything else I should be looking for?
> In general, something like a wiki page with performance tips would be very useful for D newcomers like me! :)

Without seeing the source there is nothing we can do.
Usually performant d-code looks quite diffrent from java code.
For example to avoid the gc :)
January 23, 2017
> Without seeing the source there is nothing we can do.
> Usually performant d-code looks quite diffrent from java code.
> For example to avoid the gc :)

Well it is actually ODE solver from Numerical recipes (originally in C++) that I am trying to do in D. Code translation seems very straightforward. Maybe there's someone around who has done that already? There's not much object creation going on there, mostly loops over arrays, so I assume GC is not an issue.
January 23, 2017
On Monday, 23 January 2017 at 12:13:30 UTC, albert-j wrote:
> Well it is actually ODE solver from Numerical recipes (originally in C++) that I am trying to do in D. Code translation seems very straightforward. Maybe there's someone around who has done that already? There's not much object creation going on there, mostly loops over arrays, so I assume GC is not an issue.

It really is hard without seeing the code.  When you said "from Java", my first thought was that you'd want to convert a lot of classes to structs, but you say there's not much object creation going on.

"mostly loops over arrays" makes me think of bounds checking.  Try benchmarking after compiling with -boundscheck=off to see if this is responsible for your speed difference.

By the way, the original C++ code is probably closer to good D code than the Java code.

If you really want fast numerical D code, take a look at Mir and ndslice.
January 24, 2017
On Monday, 23 January 2017 at 12:13:30 UTC, albert-j wrote:
> There's not much object creation going on there, mostly loops over arrays, so I assume GC is not an issue.

When passing arrays around, beware that static arrays are value types in D and are copied unless passed by reference.