[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Does lua optimize the collection of "anonymous" tables?
- From: William Ahern <william@...>
- Date: Sun, 17 Nov 2013 21:54:04 -0800
On Sun, Nov 17, 2013 at 09:47:47PM -0600, Andrew Starks wrote:
> Example:
>
> for i, v in pairs(args.optional_table or {}) do
> --stuff
> end
>
> If the "or {}" is triggered, is it gc'd in the same way as all other
> garbage, or is there some kind of optimization that makes this
> different?
>
> Second example:
>
> local function my_func(args)
> local first, second = args.arg1, args.arg2
> print(first, second)
> end
>
> my_func{arg1 = "hello", arg2 = "world"}
>
> Again, the anonymous table is assigned to args, but args is never
> assigned and it's never passed as an argument to something else.
>
> Is it treated differently in collection or is "garbage garbage."?
Lua 5.2 has an optional generational collector. It enabled (which can be
done at runtime), then such temporary objects would theoretically be
collected much quicker.
But there's scant evidence so far that in practice this makes Lua
applications faster, and I think the idea was floated to remove generational
collection. The stock Lua VM is exceptionally fast as-is. In the Lua
community everybody perceives stock Lua as slow relative to LuaJIT. But
stock Lua is many times faster than Perl, Python, Ruby and other similar
languages. It's faster by keeping things simple--the language and the
implementation.
If you think it'll matter to you, you should benchmark it and share your
data on this mailing-list. If it helps you, you might save the generational
GC from deletion. If not, then you would have answered your question better
than anybody on this list could have.