Naive node.js faster than naive LDC2?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Aug 22 16:38:42 UTC 2020
On 8/22/20 12:15 PM, H. S. Teoh wrote:
> On Sat, Aug 22, 2020 at 02:08:40AM +0000, bachmeier via Digitalmars-d wrote:
> [...]
>> I have no desire to dig into it myself, but I'll just note that if you
>> check the CLBG, you'll see that it's not hard to write C and C++
>> programs for this benchmark that are many times slower than Node JS.
>> The worst of them takes seven times longer to run.
>
> As described in my other post, my analysis of James' code reveals the
> following issues:
>
> 1) Using class instead of struct;
>
> 2) Using real instead of double;
>
> 3) std.math.fmax calling the C library (involving a PIC indirection to a
> shared library as opposed to inlineable native D code).
>
> Addressing all 3 issues yielded a 67% improvement (from class + real + C
> fmax -> struct + double + native fmax), or 37% improvement (from class +
> double + C fmax -> struct + double + native fmax).
>
> I don't have a Node.js environment, though, so I can't make a direct
> comparison with the optimized D version.
>
> I will note, though, that (1) and (2) are well-known performance issues;
> I'm surprised that this was not taken into account in the original
> comparison. (3) is something worth considering for std.math -- yes it's
> troublesome to have to maintain D versions of these functions, but they
> *could* make a potentially big performance impact by being inlineable in
> hot inner loops.
First off this is a great accomplishment of the V8 team. That's the
remarkable part.
Second, this is in many ways not new. JIT optimizers are great at
optimizing numeric code and loops. With regularity ever since shortly
after Java was invented, "Java is faster than C" claims have been backed
by benchmarks involving numeric code and loops. For such, the JIT can do
as good a job as, and sometimes even better than, a traditional compiler.
The way of a low-level language competes is by offering you ways to tune
code to rival/surpass JIT performance if you need to. (Of course, that
means the programmer is spending time on that, which is a minus.) I have
no doubt the D mandelbrot code can be made at least as fast as the
node.js code.
The reality of large applications involves things like structures and
indirections and such, for which data layout is important. I think JITs
have a way to go in that area.
More information about the Digitalmars-d
mailing list