surprising result with hipe compilation

Mikael Pettersson mikpe@REDACTED
Thu Oct 30 15:06:05 CET 2003


Ulf Wiger (AL/EAB) writes:
 > 
 > Här är lite kod som kan återskapa problemet:
 > 
 > Jag har klippt in en provkörning, med och utan hipe-kompilering.
 > Jag klockade genom att köra testfunktionen många gånger och 
 > jämföra bästa tiden för resp. (hipe: 13.8 ms, icke-hipe: 6.1 ms)
 > 
 > Några moduler var inte nativekompilerade: io, lists och eventuella
 > hjälpmoduler till dem.
 > 
 > /Uffe
 > 
 > [etxuwig@REDACTED]: erlc -W +native *.erl
 > [etxuwig@REDACTED]: erl -boot start_clean
 > Erlang (BEAM) emulator version 5.2.3.1 [hipe] [threads:0]
 > 
 > Eshell V5.2.3.1  (abort with ^G)
 > ...
 > 2> timer:tc(test,run,[]).

To summarise: You compile to native code and save it in files,
and then benchmark it with timer:tc as the first thing you
do in a fresh system. This gives much worse results (longer
time taken) than if the code was only in BEAM.

I also tested compiling your code into a live system and that
did not show this performance degradation.

At first I suspected a loader bug which might cause excessive
switches between BEAM and native code, but that turned out to
not be the case at all.

The problem is that when you invoke Erlang code in a fresh system,
the system internally traps the first time a not-yet-loaded module
is accessed. The module is located and loaded, internal tables are
updated, and then the access is continued. In your case, timer:tc
includes the time needed to trap-and-load your modules. You're
seeing larger values for native code than BEAM code simply because
loading native code is a heavyweight operation.

If one repeats the timer:tc call, the runtime for both BEAM and
native code is reduced to normal levels, and native code is
consistently (for your code) faster than BEAM.

Workarounds: explicitly load the necessary modules before calling
timer:tc, or even better, run it once to load the code and
prime the caches, and then again "for real".

/Mikael



More information about the erlang-questions mailing list