[erlang-questions] Erlang list equality check question
Pierre Fenoll
pierrefenoll@REDACTED
Sun Mar 25 14:04:16 CEST 2018
This sounds like a it could be compiler optimization.
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.
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.
On Sat 24 Mar 2018 at 23:47, mko_io <me@REDACTED> wrote:
> Dear erlang community,
>
> 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.
>
> 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?
>
>
> mko_io
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
Cheers,
--
Pierre Fenoll
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180325/0e037189/attachment.htm>
More information about the erlang-questions
mailing list