[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: When is multiple assignment good style?
- From: Hisham <h@...>
- Date: Fri, 17 Mar 2017 19:41:26 -0300
On 16 March 2017 at 14:19, Javier Guerra Giraldez <email@example.com> wrote:
> On 16 March 2017 at 16:49, Chris Jones <firstname.lastname@example.org> wrote:
>> This always seems to be the argument, but is it actually valid?
>> I just benchmarked table.insert vs a local alias, in a loop, with one
>> million iterations, and the difference was 0.01s
The argument about small examples works just the same for
micro-benchmarks. Lots of things make difference in micro-benchmarks
but don't in most realistic workloads.
> sometimes it _is_ valid. In SnabbSwitch, once I found a single local
> variable missing had a 6% impact in the number of packets processed
> per second.
> of course, that was a "true" local variable, not a module-level
> upvalue, but it saved one table query on a second-level loop, so it
> did matter.
Yep! When I turned my rant into blog post, where I had the benefit of
editing, I had just written something about this:
« If you have an optimization problem you can measure and the local
variable does bring a benefit, do it in a small scope, close to your
performance-sensitive tight loop so that whoever is reading your code
can understand what is going on. »
Yours is a perfect example. :)