<div dir="ltr">On Sat, Mar 24, 2018 at 11:47 PM mko_io <<a href="mailto:me@mko.io">me@mko.io</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></blockquote><br></div><div class="gmail_quote">Normally, an equality check runs through three levels:<br><br></div><div class="gmail_quote">1. Pointer equality<br></div><div class="gmail_quote">2. Type analysis. Eterms having different tags must be different.<br></div><div class="gmail_quote">3. Value analysis, perhaps recursion/congruence checks for the subterms.<br><br></div><div class="gmail_quote">So in principle, if your X and X1 are equal at the pointer level, they should stop dong a comparison. What is a bit more likely though is that you are checking in the shell and that the shell is interpreted. So it might react a bit differently. Also, you did not tell us what X1 is, so depending on how you generated that, it might be an entirely new set of data (and this requires a deep comparison with recursion then).<br><br></div><div class="gmail_quote">The Erlang system does no hash-consing, so if you generate new data, comparisons will always be expensive.<br><br></div></div>