On 08/07/14 19:54, David Nadlinger via Digitalmars-d wrote:
And secondly, proper support for building druntime/Phobos as shared libraries and loading D shared objects dynamically has now arrived in LDC! As you might be aware, Martin Nowak has spent a considerable amount of effort on adding runtime loading capabilities to DMD and druntime during the last year or so. LDC now offers the same level of functionality, to a good part based on Martin's solid work. To build a copy of LDC with druntime/Phobos as a shared library, which is also required for proper runtime loading, simply pass -DBUILD_SHARED_LIBS=ON to CMake. Oh, and for now this is Linux-only too, sorry.
So, now that I have this running, I thought I'd give it a go trying out hap.random's benchmarks with shared and with static druntime/phobos.
Most of hap.random is pretty standalone apart from reliance on std.range and std.traits (and I think that largely for compile-time checks), so, as can be expected, most functions are not meaningfully affected by being compiled against a shared library. The handful of functions that depend on std.math seem to take a small speed hit that might not be significant.
However, the dice() function, which relies on std.algorithm.reduce, takes a substantial speed hit, taking 20% more time to run compared to when the benchmarks are compiled against a static phobos.
This is probably within the realm of normalcy, and I guess the speed hit might turn out to be smaller on a larger overall timescale/number of calls, but it seems a shame (and unexpected, as reduce is obviously templated, so I wouldn't expect to have a speed hit because of shared library linkage). Can anyone suggest an explanation?