Efficiency of big return functions?

Mikael Pettersson mikpelinux@REDACTED
Thu Aug 27 17:49:34 CEST 2020


On Thu, Aug 27, 2020 at 11:51 AM Oliver Korpilla <oliver.korpilla@REDACTED> 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.


More information about the erlang-questions mailing list