Erlang - sending large messages

Suppose I create a new local process in an erlang application and I want to send him a big message.

-module(chain_hello). start(N, Some_big_data)-> Pid1 = spawn(chain_hello, some_fun, [N]), Pid1 ! Some_big_data, io:format("done \n"). 

despite the fact that Some_big_data is a link to really big data (for example, the contents of a file) - is it copied when sending? Are there big penalties for performance?

Normally I would use some thread safe shared object (and / or mutex). Is there a solution in Erlang to avoid copying the contents of the message?

ADDED:
An interesting case is that Some_big_data is structured content - for specific: map, on which I can perform some operations.

ADDED2
Well, I see that for Erlang there is no such solution (cutting some structured data, such as a map in the workflow) - due to Erlang design. But I think this is justified by solid performance and is easily consistent with management.

+4
source share
2 answers

As a suggestion, you can only send the pid of the current process (self ()) to the process that you want to process using some_big_data. Thus, if you want to use this some_big_data, you can refer to it from the second process.

For instance:

 -module(proc1). send_big_data() -> BigData = get_some_big_data(), Pid = spawn(fun proc2:start/0), Pid ! {process_big_data, self()}, loop(Pid, BigData). loop(Pid,BigData) -> receive get_first_element -> [H|T] = BigData, Pid ! {response, H}; _ -> Pid ! {nothing} end, loop(Pid). 

(Sorry for possible syntax errors).

+5
source

In the Erlang Performance Guide :

All data in messages between Erlang processes are copied, with the exception of the refc binary files on the same Erlang node.

Yes, you should avoid sending large terms between processes. If you need to send a lot of data, send it as a binary file.

+6
source

Source: https://habr.com/ru/post/1344803/