lua-users home
lua-l archive

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

Hi Tim,

On Thu, Sep 5, 2013 at 4:03 PM, Tim Hill <> wrote:
> On Sep 5, 2013, at 7:31 AM, Roberto Ierusalimschy <> wrote:
>>> On Wed, Sep 4, 2013 at 8:33 PM, Tom N Harris <> wrote:
>>>> On Monday, September 02, 2013 03:14:08 PM Emil Renner Berthing wrote:
>>>>> +LUA_API void  (lua_setstatedata) (lua_State *L, void *sd);
>>>>> +LUA_API void *(lua_getstatedata) (lua_State *L);
>>>> What's the problem with storing a lightuserdata in the registry?
>>> Performance, mostly. That's a table lookup worth of overhead for every
>>> function that needs to fetch it. A C function accessing a field in the
>>> lua_State is substantially faster.
>> Did you benchmark it for any real case (that is, a case that will waste
>> some time doing something useful with the retrieved pointer)?
>> -- Roberto
> Yes I did. The C API is a mix of heavy-ish functions that do a  chunk of work, and some very light operation that just get/set values from a structure; it's these light ones that concerned me.
> On an x86 system compiled for 64-bit code (cannot recall the CPU, but was recent pedigree), we saw about a 20-30% performance drop when using the registry

Use the registry how? Using a light userdata index? Using an integer
lookup in the array part?

Have you tried using C function upvalues?

A 20-30% performance drop in the application? Seems like a design
problem to me if you're calling the C function that frequently when it
won't logically do anything most of the time (as you've described

Patrick Donnelly