[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: The removal of function environments: An opportunity for optimization?
- From: Patrick Donnelly <batrick@...>
- Date: Mon, 24 May 2010 15:32:37 -0700
On Sun, May 23, 2010 at 8:42 AM, Mark Hamburg <email@example.com> wrote:
> Does this mean that the compiler could now detect functions without upvalue references and treat them as constants so that we don't reconstruct them over and over again? (The presence of function environments stood in the way of doing so in the past.)
> Today, one could lift such definitions out of the code and explicitly store them in local variables, but doing so can break the flow of the code for reading.
While on the subject of cheap closures, I thought having a way to
signal an object (closure or table) is a "constant" and should only be
created when the Function is being loaded (the prototype is created).
Something like this:
string.gsub(s, ".", @function(a) --[[ ... ]] end)
So the above would create the pattern function when the above chunk is
loaded. The code would simply index the "constant" closure when
calling string.gsub. (A better name would probably be Singleton
instead of constant.)
Ideally this would also work for tables as well.
- Patrick Donnelly