lua-users home
lua-l archive

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

On 16 March 2017 at 14:19, Javier Guerra Giraldez <> wrote:
> On 16 March 2017 at 16:49, Chris Jones <> 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. :)

-- Hisham