[erlang-questions] The inner workings of erlang:element/2

Raimo Niskanen <>
Fri Sep 11 10:40:49 CEST 2015


On Fri, Sep 11, 2015 at 11:17:13AM +1200, Richard A. O'Keefe wrote:
> 
> On 11/09/2015, at 12:14 am, Adam Krupicka <> wrote:
> 
> >>> I was recently profiling some code and noticed that erlang:element/2
> >>> doesn't show up in neither eprof nor fprof. How is this possible? Is the
> >>> compiler being smart here and rewriting
> >>> 
> >>> X = erlang:element(3, A)
> >>> 
> >>> with
> >>> 
> >>> {_, _, X} = A?
> 
> % cat >elt.erl
> -module(elt).
> -export([elt/1]).
> 
> elt(X) -> element(3, X).
> <EOF>
> % erlc +"'S'" elt.erl
> % cat elt.S
> <snip>
> {function, elt, 1, 2}.
>   {label,1}.
>     {line,[{location,"elt.erl",4}]}.
>     {func_info,{atom,elt},{atom,elt},1}.
>   {label,2}.
>     {line,[{location,"elt.erl",4}]}.
>     {bif,element,{f,0},[{integer,3},{x,0}],{x,0}}.
>     return.
> <snip>
> 
> This does not contain a function call.

True, but most {bif,...} calls are traceable.  The loader translates this
particular bif call to an virtual machine instruction that happens to not
be traceable.

> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list