Is Erlang really fast, given that he has many copies of memory under the hood?

I am new to Erlang, I understand that the language uses the actor model design and creates the concept of an easy process, which is the key to high parallel programming. But he also uses a functional programming paradigm that imposes benchmark transparency. This means that the variable cannot be changed after assignment. So, I see many similar functions, such as:

gb_trees:delete(Key, Tree1) -> Tree2

When we remove a key from a tree, we really create a completely new tree. Does this mean that we are cloning all the remaining nodes of Tree1 here under the hood?

If so, is this language really suitable for high-performance server development?

Thank!

+5
source share
1 answer

In the case of a tree, you only need to copy the nodes that are actually changing. Let's say you have a tree:

       A
      / \
     /   \
    B     C
         / \
        D   E

If you call your method delete_treewith B as an argument, the only node you need to copy is A, since the CDE subtree is still the same as before the operation.

In addition, if you do not use Tree1 after the operation and only use the resulting tree, the compiler can modify the operation to change the tree directly, which can be faster.

These operations are not very expensive, and for most data structures the excess copy overhead is very small. For some things (i.e. large images loaded as arrays of bytes) you may need creative solutions .

Erlang , . , , 1- , . , , , , , .

+10

All Articles