lua-users home
lua-l archive

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


If the table doesn't already exist, then you almost certainly want to avoid
building it since building it and then indexing it is almost certainly more
expensive.

In the case where it already exists, things seem a bit less clear cut though
it's basically a question of where to do the table indexing. My guess would
be that for the code you wrote, it would be better to do the table indexing
in Lua since lua_pushliteral has to find the corresponding Lua string. If
you pre-registered the strings -- or registered them on your first pass --
you could avoid that issue.

Another thing to note is that if you build multi-threading support into Lua,
a frighteningly large number of calls involve locking and unlocking the Lua
mutex and this can have a measurable impact on performance. (I think I saw a
factor of two for stuff that crossed the Lua/C boundary a lot and this was
without contention for the mutex).

Mark

on 9/24/03 1:50 PM, Kevin Baca at lualist@aidiastudios.com wrote:

> My hope was that someone with better knowledge of the VM than myself
> might be able to shed some light.
> 
> My initial thoughts were that in lua it's better to pass more parameters
> on the stack (when calling a lua_CFunction) than passing a table because
> on the C side it becomes expensive to access the table.
> 
> This is counter to C/C++ where it is usually more optimal to pass a
> single reference parameter containing parameters than to pass many
> parameters.
> 
>> 
>> 
>> One thing beats it - if someone else already knows the answer :)
>> 
>>> 
>>>> So, my question is, in terms of performance, which is better?
>>> 
>>> Nothing beats measurement to answer such questions.
>>> 
>>> -- Roberto
>>> 
>> 
>