lua-users home
lua-l archive

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

----- Ursprüngliche Message -----

> Von: Steve Litt <>
> An:
> CC: Leo Romanoff <>
> Gesendet: 21:18 Freitag, 26.Juli 2013
> Betreff: Re: Question about accessing Lua tables and arrays faster


> 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.

More results in the meantime:

I have created a version of iterations, where I use 

  rawset(t, i, rawget(t, i) + 1) 
instead of 
  t[i] = t[i] + 1 
to skip any __index() and __newindex() calls completely.

And according to my tests rawget/rawset slow down array operations significantely compared to a simple Lua's t[i] access without metatables. Basically, rawset and rawget a C functions exposed via a standrad Lua C library. Therefore each invocation of these functions introduces the almost the same overhead as in case of my own C-based vector implementation (and obtained timings confirm it). Using simple t[i] = t[i] + 1 seems to be way more efficient, because it happens completely on Lua side and does not require and Lua->C function invocations.