[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Temporary local variables
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 2 Jan 2013 16:00:46 +0200
2013/1/2 Marc Lepage <mlepage@antimeta.com>:
> 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.
You're allowed only 200 local variables at a time (limit set in lparser.c,
can't be more than 250).
However, if you put do...end around each of your blocks, each block
starts with a new allocation of local variables.