<div dir="ltr">> I think Erlang needs a linter. <br><br>Definitely. Generally speaking, a code rewrite tool (to unquote atoms ;))<br><br>> list comprehensions but I can’t find it right now. <br><br>It's closed source now, and afaik is not ready for production.<br><br>On Sun, Mar 25, 2018 at 2:49 PM, Oliver Korpilla <<a href="mailto:Oliver.Korpilla@gmx.de">Oliver.Korpilla@gmx.de</a>> wrote:<br>><br>> Hello.<br>><br>> I'm trying to understand this topic as well.<br>><br>> I was under the impression that if you generated two lists independently from each but with identical elements they would not share memory, but let's say you took part of an existing list or append to an existing list they do. If this assumption is true, list comparison could only short circuit for lists indeed sharing memory.<br>><br>> And it seems it does (latest OTP 20.3 used on arm):<br>><br>> 8> List1 = lists:seq(1,10000).<br>> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,<br>> 23,24,25,26,27,28,29|...]<br>> 9> List2 = lists:seq(1,10000).<br>> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,<br>> 23,24,25,26,27,28,29|...]<br>> 10> timer:tc(fun() -> List1 =:= List2 end).<br>> {279,true}<br>> 11> timer:tc(fun() -> List1 =:= List1 end).<br>> {20,true}<br>> 12> List3 = [ 0 | List1 ].<br>> [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,<br>> 23,24,25,26,27,28|...]<br>> 13> timer:tc(fun() -> List1 =:= List3 end).<br>> {22,false}<br>> 14> [ _ | List4 ] = List3.<br>> [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,<br>> 23,24,25,26,27,28|...]<br>> 15> timer:tc(fun() -> List1 =:= List4 end).<br>> {23,true}<br>><br>> 10> compares two independently generated lists and does a full walk, it seems.<br>> 11> compares the same con cell and performs much better.<br>> 13> up to 15> compares two lists that share con cells and performs much better<br>><br>> It seems that BEAM already short circuits list walks if it finds a shared con cell.<br>><br>> I'm a bit confused about the example mko_io gives though as te definition of X1 is not given? Also, what system were you testing on with what OTP version? Your numbers seem much worse than even on my Raspberry Pi 3.<br>><br>> Cheers,<br>> Oliver <br>> <br>><br>> Gesendet: Sonntag, 25. März 2018 um 14:04 Uhr<br>> Von: "Pierre Fenoll" <<a href="mailto:pierrefenoll@gmail.com">pierrefenoll@gmail.com</a>><br>> An: mko_io <<a href="mailto:me@mko.io">me@mko.io</a>><br>> Cc: <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>> Betreff: Re: [erlang-questions] Erlang list equality check question<br>><br>> This sounds like a it could be compiler optimization. <br>> However I think it would be better to have a lint tool suggesting to rewrite that equality comparison by extracting the head and comparing only that. Maybe code from Dialyzer could be reused to find such cases and others, providing performance tips as well as style and maybe even architectural suggestions. <br>> <br>> I think Erlang needs a linter. Do you guys know any such tool? Kostis has one that rewrites calls to lists:map/2 into list comprehensions but I can’t find it right now. <br>> <br>><br>> On Sat 24 Mar 2018 at 23:47, mko_io <<a href="mailto:me@mko.io">me@mko.io</a>[mailto:<a href="mailto:me@mko.io">me@mko.io</a>]> wrote:Dear erlang community,<br>><br>> I’ve been reading the beam book recently, just learned the memory representation of a list is just a con cell which occupy a machine word which 2 bit tag. So It’s make sense that appending a new element on a big list is a small operation. timer:tc/1 shows X = lists:seq(1, 10000) takes 1184us and X2 = [0 | X] only takes 2 us.<br>><br>> But X =:= X1 takes 600us, which shows it walks the whole list to do the equality check, my question is why not just do a cheap con cell immediate comparison since erlang variables don’t vary and tl(X2) points to X1. Is there any method to do the cons equality comparison?<br>><br>><br>> mko_io<br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>[mailto:<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>]<br>> <a href="https://mltrk.io/link/http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions--/J6cxUucCcFR1wjxj046o">http://erlang.org/mailman/listinfo/erlang-questions--</a><br>><br>> <br>> Cheers,<br>> -- <br>> Pierre Fenoll<br>> _______________________________________________ erlang-questions mailing list <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a> <a href="https://mltrk.io/link/http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions/J6cxUucCcFR1wjxj046o">http://erlang.org/mailman/listinfo/erlang-questions</a>[<a href="https://mltrk.io/link/http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions/J6cxUucCcFR1wjxj046o">http://erlang.org/mailman/listinfo/erlang-questions</a>]<br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>> <a href="https://mltrk.io/link/http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions/J6cxUucCcFR1wjxj046o">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br><br><br>--<br>With best regards,<br> Roman Galeev,<br> +420 702 817 968<br><div class="gmail_extra">
</div><img src="https://mltrk.io/pixel/J6cxUucCcFR1wjxj046o?rid=J6cxUucCcFR1wjxj046o" width="1" height="1" border="0"></div>