Optimize some ++ situations
Wed Oct 28 07:02:56 CET 2020
On Tue, Oct 27, 2020 at 5:09 PM Christofer Tornkvist (ctornkvi)
> would it be a stupid suggestion to let add a parameter of list type
> to all built-in and library functions returning a list.
No, but it is unlikely that we would consider implementing such an
It would be better to show real world use cases for the list functions
that would truly gain from that optimization.
> If this was the case, the complier can optimize code like;
> erlang:atom_to_list(Atom) ++ MyTail
> erlang:atom_to_list(Atom, MyTail)
In many cases you can build an iolist instead:
and flatten it later or send it to one of the many functions or BIFs
that accept iolists.
> lists:map(Fun, List) ++ MyTail
> lists:map(Fun, List, MyTail)
The compiler will optimize it if you use a list comprehension instead
[Fun(E) || E <- List] ++ MyTail
> Or is the compiler able to see this optimization anyhow?
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions