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

Richard A. O'Keefe ok@REDACTED
Fri Sep 11 01:17:13 CEST 2015


On 11/09/2015, at 12:14 am, Adam Krupicka <akrupicka@REDACTED> 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.




More information about the erlang-questions mailing list