lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Thu, Oct 29, 2020 at 3:53 AM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> This can be seen without benchmarking. The problem with variadic
> arguments is that every function call with them is O(n), where n is
> the number of arguments. Just the call, ignoring whatever the function
> does. [...]

This is true for non-variadic functions as well, as Lua has to prepare
the n arguments to the function. I think most calls in most languages
follow that rule. (Inline functions that do not use its parameters would
be a counter-example.)

-- Roberto

Is it in fact the case that variadic functions have additional overhead? That is,  calling `fn(a, b, c)` would be cheaper if this was defined as `function fn(a, b, c)`, rather than `function fn(...)` ?

I know there's more to this question than it appears, since one must *do* something with the arguments, and `{...}` would have different overhead from e.g. `select(1, ...)` and so on.

I had the impression that variadics carry some amount of overhead, but never benchmarked it.

For the sake of argument, we could compare:

function subber(...)
   return string.sub(...)
end

with:

function subber(str, start, finish)
    return string.sub(str, start, finish)
end

cheers,
-Sam