[erlang-bugs] Expensive module miss when code path cache is enabled

José Valim <>
Tue Nov 19 12:49:38 CET 2013


Hello OTP team,

I was experimenting with Erlang's code path cache and I have found that
some operations actually become quite slower when the code path cache is
enabled.
In particular, code:ensure_loaded/1 becomes an order of magnitude slower
when the module is not loaded and does not exist in any code path.

By inspecting the code_server source code, I have noticed that this line is
responsible for the slow down:

https://github.com/erlang/otp/blob/fb0006c937e284cefe5217d4c2a4b45ff7dfb758/lib/kernel/src/code_server.erl#L1341

Basically, every time we can't find a module, the whole code path is
rehashed. The slow down will be even bigger for larger code paths.

I tried blaming the line above with no success. Removing the line also does
not introduce failures into the code_SUITE so I am unsure if this behaviour
is by design or not. The only use case I can think for this behaviour is to
be able to load beam files that are added to code paths *after* the code
path was added to the code server but it seems an arguable behaviour
considering its effects on a module miss.

I may be missing something obvious that justifies the current behaviour
and, if so, I believe we should at least document it. I will be glad to
send a patch if the OTP team agrees with it.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131119/db39b958/attachment.html>


More information about the erlang-bugs mailing list