This introduces no overhead in runtime in practice. Erlang compiler use SSA graph intermediate code representation form where removing such line becomes trivial.
Even if you do
y = x
f(y)
It will be compiled to exactly the same byte and native code as f(x)
It is a great question.
First of all, structures in Elixir are immutable, but not in a sense of immutability like in Rust or const in C. They are never copied on passing as an argument, but they may be copied (or partially copied) on mutation. So no, it won’t be copied.
Second, is that there are some other optimizations which might happen. Consider this code
def example do
x = {f(), g(), h()}
my_func(:error, x)
end
If my_func is defined in the same module and inline is enabled, it may get compiled to something like
def example do
f()
g()
h()
some_thing_else()
end
You can see that operation of constructing the tuple is removed and my_func was inlined.
But if my_func was defined in some other module, it won’t be inlined and code would be compiled without any optimizations.


















