How Expensive is functions

I was wondering how expensive functions are
Im not talking about what inside a function instead functions themselves

function a() end
a()

Like that. How expensive would that be?
does functions have a enough sizable footprint to be thought about?

As far as I’m aware the independent ‘expense’ or memory space used up by functions is null or close to that since I’ve never faced any issues due to the influx of the same on Lua nor on other coding languages.

And as far as I’m aware the real expensive part depends not upon the function itself but rather relies on the length and memory required by the contents of the function in dispute.

1 Like

The function name is defined on the stack as a reference to the callable object. It does occupy memory space, but the exact amount of memory is unknown.

Lua function types would take, on average, 20 bytes of memory on function invoke if nothing were to be passed into the parameter list. In the case of adding length to the process, the size would depend on the data types being passed through. If we pass a table(40 bytes) or an integer(base64) 3 bytes.

I suggest using garbage collection in regular Lua to find your answer.

1 Like