lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Say I have an object with about a dozen properties A-L.

I want to process them in small groups, something like:

local a, b = o.a, o.b
if a or b then
    doSomethingWithAB(a, b)
end

local c, d = o.c, o.d
doSomethingWithCD1(c, d)
doSomethingWithCD2(c, d)

It happens that I don't need to use AB after I go on to CD. Yet, I get them into separate local variables.

I am just wondering, will it be any kind of performance gain if I were to reuse the same local variables for CD as for AB?

I mean, what would be going on under the hood, and could a gain be reasonably expected (assuming these functions are called often on lots of objects)? Would it reduce the amount of memory churn?

I think it's more readable as it is, but if it were good practice to reduce the amount of locals in this function (say from 12  to 2) for a gain I'd be willing to do that. Mostly I'm just curious what the difference would be.