<div dir="ltr"><div>Why don't we use the flag which is not documented and not used by default when "+native" flag is enabled?<br><br>This is table comparison<span class="im"><span><br><a href="https://drive.google.com/open?id=1P3nYD0EZXL16TqQ0WStqa3RqWt6riqd9MH25YsmnGmE" target="_blank">https://drive.google.com/open?id=1P3nYD0EZXL16TqQ0WStqa3RqWt6riqd9MH25YsmnGmE</a></span></span><br><br>There is +strict_record_updates flag in Erlang which is used to disable setelement for record updating. In this case get_tuple_element, put and put_tuple are used instead of setelement. Unlike setelement, they create new record with applied changes. For example, I wrote a simple method (function) working with record, and translated it to a native code.<br><br>By the way, as we can see in this table, the +strict_record_updates flag achieves greater speedup when used with +native flag. Likewise, the "put" flag is better than "setelement" when used with +native.<br><br>-module(testing).<br>-compile(export_all).<br>-define(COUNT, 100000000).<br>-record(big_record,<br>    {<br>        id1 = 1,<br>        id2 = 2,<br>        id3 = 3,<br>        id4 = 4,<br>        id5 = 5,<br>        id6 = 6<br>    }).<br>big_record_1_update(_Config) -><br>    State = #big_record{},<br>    call_big_record_1_update(?COUNT, State).<br>call_big_record_1_update(0, _) -><br>    #big_record{id1 = 0};<br>call_big_record_1_update(Number_test, State) -><br>    call_big_record_1_update(Number_test - 1, State#big_record{id1 = Number_test}).<br><br><br>%%%%%%%%%%%%%%%%%%%%%%%%%%%<br><br><br>erl -S testing.erl<br>{function, all, 0, 2}.<br>  {label,1}.<br>    {line,[{location,"testing_06_SUITE.erl",5}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,all},0}.<br>  {label,2}.<br>    {move,{literal,[big_record_1_update,big_record_2_update,<br>                    big_record_3_update]},<br>          {x,0}}.<br>    return.<br><br>{function, big_record_1_update, 1, 4}.<br>  {label,3}.<br>    {line,[{location,"testing_06_SUITE.erl",18}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,big_record_1_update},1}.<br>  {label,4}.<br>    {move,{literal,{big_record,1,2,3,4,5,6}},{x,1}}.<br>    {move,{integer,100000000},{x,0}}.<br>    {call_only,2,{f,6}}.<br><br>{function, call_big_record_1_update, 2, 6}.<br>  {label,5}.<br>    {line,[{location,"testing_06_SUITE.erl",21}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,call_big_record_1_update},2}.<br>  {label,6}.<br>    {test,is_eq_exact,{f,7},[{x,0},{integer,0}]}.<br>    {move,{literal,{big_record,0,2,3,4,5,6}},{x,0}}.<br>    return.<br><br> %% This is interesting moment<br>__________________________________________<br> {label,7}.<br>    {allocate_zero,1,2}.<br>    {line,[{location,"testing_06_SUITE.erl",24}]}.<br>    {gc_bif,'-',{f,0},2,[{x,0},{integer,1}],{x,2}}.<br>    {test,is_tuple,{f,8},[{x,1}]}.<br>    {test,test_arity,{f,8},[{x,1},7]}.<br>    {get_tuple_element,{x,1},0,{x,3}}.<br>    {test,is_eq_exact,{f,8},[{x,3},{atom,big_record}]}.<br>    {move,{x,2},{y,0}}.<br>    {move,{x,0},{x,2}}.<br>    {move,{integer,2},{x,0}}.<br>    {line,[{location,"testing_06_SUITE.erl",24}]}.<br>    {call_ext,3,{extfunc,erlang,setelement,3}}.<br>    {move,{x,0},{x,1}}.<br>    {move,{y,0},{x,0}}.<br>    {call_last,2,{f,6},1}.<br>__________________________________________<br><br>{label,8}.<br>    {move,{literal,{badrecord,big_record}},{x,0}}.<br>    {line,[{location,"testing_06_SUITE.erl",24}]}.<br>    {call_ext,1,{extfunc,erlang,error,1}}.<br><br><br>%%%%%%%%%%%%%%%%%%%%%%%%%%%<br><br><br>erl -S +strict_record_updates testing.erl<br>{function, all, 0, 2}.<br>  {label,1}.<br>    {line,[{location,"testing_06_SUITE.erl",5}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,all},0}.<br>  {label,2}.<br>    {move,{literal,[big_record_1_update,big_record_2_update,<br>                    big_record_3_update]},<br>          {x,0}}.<br>    return.<br><br>{function, big_record_1_update, 1, 4}.<br>  {label,3}.<br>    {line,[{location,"testing_06_SUITE.erl",18}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,big_record_1_update},1}.<br>  {label,4}.<br>    {move,{literal,{big_record,1,2,3,4,5,6}},{x,1}}.<br>    {move,{integer,100000000},{x,0}}.<br>    {call_only,2,{f,6}}.<br><br>{function, call_big_record_1_update, 2, 6}.<br>  {label,5}.<br>    {line,[{location,"testing_06_SUITE.erl",21}]}.<br>    {func_info,{atom,testing_06_SUITE},{atom,call_big_record_1_update},2}.<br>  {label,6}.<br>    {test,is_eq_exact,{f,7},[{x,0},{integer,0}]}.<br>    {move,{literal,{big_record,0,2,3,4,5,6}},{x,0}}.<br>    return.<br><br> %% This is interesting moment<br>__________________________________________<br>  {label,7}.<br>    {line,[{location,"testing_06_SUITE.erl",24}]}.<br>    {gc_bif,'-',{f,0},2,[{x,0},{integer,1}],{x,2}}.<br>    {test,is_tuple,{f,8},[{x,1}]}.<br>    {test,test_arity,{f,8},[{x,1},7]}.<br>    {get_tuple_element,{x,1},0,{x,3}}.<br>    {get_tuple_element,{x,1},2,{x,4}}.<br>    {get_tuple_element,{x,1},3,{x,5}}.<br>    {get_tuple_element,{x,1},4,{x,6}}.<br>    {get_tuple_element,{x,1},5,{x,7}}.<br>    {get_tuple_element,{x,1},6,{x,8}}.<br>    {test,is_eq_exact,{f,8},[{x,3},{atom,big_record}]}.<br>    {test_heap,8,9}.<br>    {put_tuple,7,{x,1}}.<br>    {put,{atom,big_record}}.<br>    {put,{x,0}}.<br>    {put,{x,4}}.<br>    {put,{x,5}}.<br>    {put,{x,6}}.<br>    {put,{x,7}}.<br>    {put,{x,8}}.<br>    {move,{x,2},{x,0}}.<br>    {call_only,2,{f,6}}.<br>__________________________________________<br><br>  {label,8}.<br>    {move,{literal,{badrecord,big_record}},{x,0}}.<br>    {line,[{location,"testing_06_SUITE.erl",24}]}.<br>    {call_ext,1,{extfunc,erlang,error,1}}.<br></div><span class="im"></span></div>