<div dir="ltr">Hello OTP team,<div><br></div><div>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.</div><div>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.</div>
<div><br></div><div>By inspecting the code_server source code, I have noticed that this line is responsible for the slow down:</div><div><br></div><div><a href="https://github.com/erlang/otp/blob/fb0006c937e284cefe5217d4c2a4b45ff7dfb758/lib/kernel/src/code_server.erl#L1341">https://github.com/erlang/otp/blob/fb0006c937e284cefe5217d4c2a4b45ff7dfb758/lib/kernel/src/code_server.erl#L1341</a></div>
<div><br></div><div>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.</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div><div><div>
<div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div>
<span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div>
<div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div></div>
</div></div>