[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Unnecessary New Closures
- From: roberto@... (Roberto Ierusalimschy)
- Date: Thu, 6 Sep 2007 08:34:35 -0300
> I'm curious about a problem I encountered with this:
> table.sort(sometable, function(a, b) return a < b end);
> If this is executed repeatedly this creates a new closure every time.
> Because, as I understand it, this function is compiled as a prototype
> with no upvalues, why is a new closure created every time? Seems
> unnecessary, let alone inefficient. Would it not be possible for the
> lua compiler to just get the reference to the function (closure) and
> pass it?
Unfortunately not :( The compiler has no way to know whether the
closure is "escaping" through 'table.sort' (e.g., being stored in
global variables), and each new closure may have its own independent