[erlang-questions] Erlang and Akka
Richard A. O'Keefe
ok@REDACTED
Sun Aug 31 23:40:30 CEST 2014
On 29/08/2014, at 3:40 PM, Xiao Jia wrote:
> On Fri, Aug 29, 2014 at 6:10 AM, Richard A. O'Keefe <ok@REDACTED> wrote:
>
> I have known *interpreted* Scheme to run faster than
> *compiled* C++.
>
> What is the underlying issue? I always thought interpreted languages cannot achieve good cache efficiency so they are doomed to be much slower given that the same algorithms and data structures are used.
Even that is not true.
I used to work at Quintus. Quintus Prolog compiled Prolog to
(a variant of) the Warren Abstract Machine, which was implemented
as a threaded code interpreter. One of our competitors compiled
to native code. For a 1 page program, they ran 4 times faster than
us. For a 10 page program, the two systems ran at the same speed.
For a 100 page program, the threaded code system ran about 4 times
faster than the native code system.
Oddly enough, the reason was precisely "good cache efficiency".
The threaded code emulator was less than 64 k of code. It got
into L1 instruction cache and stayed there. The actual threaded
code was quite compact, so you could have quite a bit of it in
L2 cache. The native code was much bulkier.
However, in the Scheme -vs- C++ example, there were two issues.
(1) C++ strings were grotesquely inefficient in that system.
(2) The code was fairly allocation-heavy, and while the C++
version did need less memory, it spent a *lot* more time
managing it.
This is a claim about one specific implementation of Scheme and
one specific implementation of C++, at a specific time, on a
specific machine that's not on the market any more. Nothing can
be inferred from it about Scheme and C++ in general.
There is perhaps a general warning:
- the fact that a LANGUAGE can be compiled to efficient code
does not imply that its LIBRARY is efficient.
I could give other examples of interpreted languages beating
compiled ones. What the heck, I shall.
- Prolog (emulated) vs Fortran (optimised native code).
The Fortran program was written by someone else first (in
Fortran 77). I then rewrote it in Prolog using a sparse
matrix data structure that was very easy in Prolog and
would have been very hard in Fortran. (Modern Fortran is a
very different thing.)
- AWK (threaded code, emulated in C) vs Java (JIT native code).
The culprit was java.io.RandomAccessFile.
- AWK vs Java again. This time it's 40 more years of
programmer experience leading to a much more economical
program.
There's another general issue to be gleaned here:
- the fact that a LANGUAGE can be compiled to efficient code
does not imply that efficient ALGORITHMS will be easy to
conceive or express in it.
Java seems to be particularly bad here. You *can* write fast
clean code in it, but somehow, I never meet any.
More information about the erlang-questions
mailing list