For a function inside another function, does Lua “instantiate” the inner function on each call to the outer function? If so, would bar() in the code below perform worse than foo()?
local function a()
print 'a'
end
function foo()
a()
end
function bar()
function b()
print 'b'
end
b()
end
Test case 1:
aandbboth global, no embedding.User time: 1.74s.
Test case 2:
alocal,bglobal, no embedding.User time 1.39s.
Test case 3:
aandbboth local, no embedding.User time 1.2s.
Test case 4:
aembedded inb,aglobal,blocal.User time: 2.79s. (!)
Test case 5:
aembedded inb, both local.User time: 2.53s.
Result summary: