[erlang-questions] What is the fastest way to check if a function is defined in a module?
Tristan Sloughter
t@REDACTED
Tue Mar 6 21:35:45 CET 2018
Ooh, that looks similar, but better, to what we did in Erleans:
erlang:function_exported(Module, module_info, 0) orelse
code:ensure_loaded(Module), case erlang:function_exported(Module, FunctionName, Arity) of
true ->
erlang:apply(Module, FunctionName, Args);
false ->
Default
end.
I guess we should likely switch to `erlang:module_loaded(M)` instead of
checking if `module_info` is exported. Thanks!
Would be nice to have it patched though :)
--
Tristan Sloughter
"I am not a crackpot" - Abe Simpson
t@REDACTED
On Tue, Mar 6, 2018, at 12:23 PM, Richard Carlsson wrote:
> I was actually considering submitting such a patch a while back, but
> one argument against making that short-cut could be that operations
> against the code server should be serialized. On the other hand I
> haven't yet come up with an example where the short-cut would make a
> difference that couldn't already happen due to processor scheduling.>
>
> /Richard
>
> 2018-03-06 16:40 GMT+01:00 Michał Muskała <michal@REDACTED>:
>>
>> On 6 Mar 2018, 16:36 +0100, Richard Carlsson
>> <carlsson.richard@REDACTED>, wrote:>>
>>
>>>
>>> is_exported(M, F, A) ->
>>> case erlang:module_loaded(M) of
>>> false -> code:ensure_loaded(M);
>>> true -> ok
>>> end,
>>> erlang:function_exported(M, F, A).
>>>
>>> (code:ensure_loaded() is slow compared to the fast call to
>>> erlang:module_loaded(), even if the module is already in memory).>>>
>>
>> I was recently wondering about this. Is there a reason
>> code:ensure_loaded() does not short circuit using
>> erlang:module_loaded()? It could probably even skip the request to
>> the code server entirely in case the module is already loaded.>>
>>
>> Michał.
>>
>>
> _________________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180306/9d81170b/attachment.htm>
More information about the erlang-questions
mailing list