[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Question about accessing Lua tables and arrays faster
- From: Steve Litt <slitt@...>
- Date: Fri, 26 Jul 2013 15:18:35 -0400
On Fri, 26 Jul 2013 11:42:35 -0700 (PDT)
Leo Romanoff <email@example.com> wrote:
> ----- Ursprüngliche Message -----
> > Von: Steve Litt <firstname.lastname@example.org>
> > Two more things, and the first one is this: I have no doubt that the
> > others are faster for going over and incrementing each element. But
> > I'm wondering if, for more ambitious usages of elements, you could
> > put the element processing in a metatable, and if that would speed
> > things up.
> Can you elaborate a bit? What do you mean by putting element
> processing in a metatable? I'm not sure I understand what you mean.
> Do you mean that __index method should do the actual processing, e.g.
> increment a value?
Yes. __index() and __newindex()
> > If you try the "process the element using the metatable" approach,
> > please let us know how it works.
> I'd be happy to try out and provide feedback once you explain me
> what "process the element using the metatable" exactly means ;-)
Just what you mentioned earlier: have the metatable's __index() and
__newindex() do some of the actual computation. So if you're
incrementing each position, have the __index increment it every time
you read. Or every time you read if some flag is set.
By the way, there's a rawget(t, i) and a rawset(t, k, v) that skip
__index() and __newindex() respectively, but PIL says those don't gain
you any performance.
Steve Litt * http://www.troubleshooters.com/
Troubleshooting Training * Human Performance