[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The removal of function environments: An opportunity for optimization?
- From: Duncan Cross <duncan.cross@...>
- Date: Mon, 24 May 2010 13:57:48 +0100
On Sun, May 23, 2010 at 4:42 PM, Mark Hamburg <mark@grubmah.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.
>
> Mark
>
>
It does sound like a pretty good idea. Can anyone think of a realistic
circumstance where functions being identical values where they didn't
used to be would cause a big problem?
To explain what I mean a bit more:
local t = {}
for i = 1, 100 do
local f = function() return "hi"; end
t[f] = true
end
for func in pairs(t) do
print(func())
end
...would print "hi" 100 times at the moment, but only once if we had
this optimisation. But this is obviously a very contrived example, the
question is: is there much real-world code out there that could be
affected in a similar way?
-Duncan