Re: Efficiency of big return functions?
Mikael Pettersson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAM43=SP-JK1_tcgy7ey2kXzYDvV+guuU6d+Z6k9O4zfhR9uKkQ@mail.gmail.com> |
On Thu, Aug 27, 2020 at 11:51 AM Oliver Korpilla <[email protected]> wrote: > My question is - how do I efficiently return a big static value (a list > of maps with no parameters to change their construction) from a > function? Does BEAM optimize this? Or is the value constructed when the > function is called? A static term should become a compile-time literal. When the code is loaded, that literal is put in the global literals pool, and the function's reference to that value is just a constant pointer. So there's no run-time construction of that value. Returning any value from a function call is just placing that value in a register. There is no allocation or copying of heap data during returns (or when passing such data as parameters to functions). Allocation and copying does occur when storing data in ETS, retrieving data from ETS, and when sending data to a process.