lua-users home
lua-l archive

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



On 19-Aug-04, at 6:21 PM, Edgar Toernig wrote:

Maybe.  But the whole point of the change is to avoid allocating
a (usually short-living) heap object on each vararg-function
invocation.

I understand that. Personally I'd be more interested in an
optimisation which avoids allocating short-lived heap objects
for curried functions, for example.

The tuple proposal is an attempt to reduce the number of short-lived
heap objects created for vararg-function invocations from three to one.
That's maybe not as good as zero, but I think it has other advantages.

Your tuple proposal just introduces a new datatype.  All the
syntax extensions could equally well be implemented for tables.
Where's the tuple variant better than a regular table?  Any
performance differences would only be implementation details.

Well, the same could be said for the ... hack; the performance
difference is only an implementation detail. One could attempt to
optimise vararg calls through a different implementation which did
not alter the syntax at all.

Now, it's true that the tuple proposal is (more or less) a new datatype,
although it is actually implemented on top of an existing datatype
(that is, a C-function). The implementation, shorn of the new syntax,
is less than 10 lines of code.

In fact, my first thought here was, well why not just optimise tables
a bit more. That is surely possible. But functional tuples, even with a
naive implementation, turn out to be a massive performance win in a number
of common problems.

For example, they provide a handy way to collect multiple return values,
an issue I believe you yourself noted in an earlier posting on the subject
of ...

Also, they considerably simplify the implementation of tables which logically have multiple values; there are other ways of dealing with this, of course, but functional tuples (in my opinion) lead to cleaner implementations: tables of tables are of course possibly but they are bulky enough that one is motivated to avoid them, while keeping each value in a separate table is fast
but complicates the code.

So one question is, are functional tuples useful enough to add syntax to the
language (and/or make some other adjustments)?

I combine that with another question: is the ... thing worth a fairly considerable complication to the Lua core when functional tuples provide a reasonably optimised solution to the varargs issue, along with other issues?

On balance, my vote is with functional tuples. For what that's worth.