diff options
author | Björn Gustavsson <[email protected]> | 2011-11-17 20:25:48 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-11-23 10:40:33 +0100 |
commit | ad2962278f347a5d0341c0d5d11cbb71c83eb35b (patch) | |
tree | 13a15497b3f109a395fbabd7aa81ceb287b10c23 /lib | |
parent | b3a8ad925c72bc77d3509ef8dce155d65dc1548b (diff) | |
download | otp-ad2962278f347a5d0341c0d5d11cbb71c83eb35b.tar.gz otp-ad2962278f347a5d0341c0d5d11cbb71c83eb35b.tar.bz2 otp-ad2962278f347a5d0341c0d5d11cbb71c83eb35b.zip |
Avoid slow code loading of BEAM code in a hipe-enabled emulator
On my Linux computer, building the entire Erlang/OTP system
with hipe disabled took about 8 minutes. With hipe enabled,
but without any native code, the build took about 23 minutes,
i.e. more than 3 times slower. (The computer has 4 cores, and
I used 'make -j6'.)
On my eight-core Mac (running 'make -j10') there was only a slight
slowdown when hipe was enabled.
The culprit is hipe_unified_loader:post_beam_load/1, which will be
called every time a module is loaded (even if the module contains no
native code). If post_beam_load/1 is called in a hipe-enabled
emulator, it will block multi-scheduling, even if no work needs to be
done. Apparently the cost for blocking multi-scheduling can vary
greatly, depending on the operating system and system load.
As a quick and conservative fix, don't call post_beam_load/1 unless
some native code has been previously loaded.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel/src/code_server.erl | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl index e3d22e7999..32a12e2b52 100644 --- a/lib/kernel/src/code_server.erl +++ b/lib/kernel/src/code_server.erl @@ -32,6 +32,8 @@ -import(lists, [foreach/2]). +-define(ANY_NATIVE_CODE_LOADED, any_native_code_loaded). + -record(state, {supervisor, root, path, @@ -97,6 +99,8 @@ init(Ref, Parent, [Root,Mode0]) -> State0 end, + put(?ANY_NATIVE_CODE_LOADED, false), + Parent ! {Ref,{ok,self()}}, loop(State#state{supervisor = Parent}). @@ -1278,20 +1282,35 @@ load_native_code(Mod, Bin) -> %% Therefore we must test for that the loader modules are available %% before trying to to load native code. case erlang:module_loaded(hipe_unified_loader) of - false -> no_native; - true -> hipe_unified_loader:load_native_code(Mod, Bin) + false -> + no_native; + true -> + Result = hipe_unified_loader:load_native_code(Mod, Bin), + case Result of + {module,_} -> + put(?ANY_NATIVE_CODE_LOADED, true); + _ -> + ok + end, + Result end. hipe_result_to_status(Result) -> case Result of - {module,_} -> Result; - _ -> {error,Result} + {module,_} -> + put(?ANY_NATIVE_CODE_LOADED, true), + Result; + _ -> + {error,Result} end. post_beam_load(Mod) -> - case erlang:module_loaded(hipe_unified_loader) of - false -> ok; - true -> hipe_unified_loader:post_beam_load(Mod) + %% post_beam_load/1 can potentially be very expensive because it + %% blocks multi-scheduling; thus we want to avoid the call if we + %% know that it is not needed. + case get(?ANY_NATIVE_CODE_LOADED) of + true -> hipe_unified_loader:post_beam_load(Mod); + false -> ok end. int_list([H|T]) when is_integer(H) -> int_list(T); |