Skip to content

Commit

Permalink
Do not attempt to load code if mode is embedded
Browse files Browse the repository at this point in the history
Erlang/OTP 25 only attempted to perform
code loading if the mode was interactive:

https://github.com/erlang/otp/blob/maint-25/lib/kernel/src/code_server.erl#L301

This check was removed in erlang#6736 as part of
the decentralization. However, we received
reports of increased cpu/memory usage in
Erlang/OTP 26.1 in a code that was calling
code:ensure_loaded/1 on a hot path. The
underlying code was fixed but, given erlang#7503
added the server back into the equation for
ensure_loaded we can add the mode check
back to preserve Erlang/OTP 25 behaviour.
  • Loading branch information
josevalim committed Oct 6, 2023
1 parent 3a914d2 commit 1acce73
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/kernel/src/code_server.erl
Expand Up @@ -339,11 +339,12 @@ handle_call({get_object_code,Mod}, _From, St0) when is_atom(Mod) ->
handle_call({get_object_code_for_loading,Mod}, From, St0) when is_atom(Mod) ->
case erlang:module_loaded(Mod) of
true -> {reply, {module, Mod}, St0};
false ->
false when St#state.mode =:= interactive ->
case wait_loading(St0, Mod, From) of
{true, St1} -> {noreply, St1};
false -> get_object_code_for_loading(St0, Mod, From)
end
end;
false -> {reply, {error,embedded}, St0}
end;

handle_call(stop,_From, S) ->
Expand Down

0 comments on commit 1acce73

Please sign in to comment.