[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Temporary local variables
- From: Marc Lepage <mlepage@...>
- Date: Tue, 1 Jan 2013 22:59:31 -0500
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
local c, d = o.c, o.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.