The short answer is that the BEAM does not do a full copy of a map for every update.
For the long answer you could refer to this book: https://www.amazon.com/Purely-Functional-Data-Structures-Okasaki/dp/0521663504 On Mon, Aug 24, 2020, at 14:28, Bulent Erdemir wrote: > Hi, > > Elixir applications, due to immutability principle, create a copy of a data > structure once that structure is modified (transformed) and if the > structure's new value is to be kept via assignment to a variable. Hence, for > example, when a Map is visited and some its members are modified , for each > modification a copy of the whole Map is created. I understand that creating a > new variable is as simple as bumping up a pointer in memory, however, the > whole Map is copied over and over again while it's being modified in the > application. In other languages without the immutability principle, only the > changed portion of the Map would be allocated in memory during a similar > operation. > > In such a situation where there's this copying overhead in almost all data > operations in an Elixir program, I would expect the system would run much > slower compared to other languages. Yet, I've not seen mention of this > problem anywhere on the web. So, probably, I'm missing something. Anyone > please would care to comment on this ? > > Regards, > Bülent Erdemir > > -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CABgUW%2BQiD_Q8bKbe8hV5Q6Lh3PbgVxthOf7zRMASA4qiwqmbrA%40mail.gmail.com > > <https://groups.google.com/d/msgid/elixir-lang-core/CABgUW%2BQiD_Q8bKbe8hV5Q6Lh3PbgVxthOf7zRMASA4qiwqmbrA%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/03738aa6-3665-4a4d-a6de-4475d0a0a228%40www.fastmail.com.
