[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_setfield vs lua_rawset
- From: Chris Marrin <chris@...>
- Date: Wed, 19 Oct 2005 14:36:47 -0700
Rici Lake wrote:
On 19-Oct-05, at 12:00 PM, Chris Marrin wrote:
But the decision was made to provide the particular variant of
lua_setfield(), which is extremely useful. And since the "raw"
variants add a useful (and sometimes critical) optimization of their
own, it seems that the equivalent lua_rawsetfield() would have been a
good choice.
Have you actually benchmarked the difference in performance between
lua_settable() and lua_rawset()? It seems to me to be hardly noticeable
in the normal case. (That's not the same situation as lua_rawseti().)
Using lua_rawset() instead of lua_settable() produces surprising results
(surprising to the client of the library, that is) because it doesn't
respect metatables. There is no difference when the table has no
metatable, or when the key already exists.
I would strongly discourage use of rawset except in cases where it is
actually necessary because you have to bypass the __newindex metamethod.
Such cases are quite rare (usually confined to implementation of
__newindex itself).
Exactly where I am using it! I am actually using it in several places
where I am setting the underlying table of my object system. This table
is an internal detail of the implementation and I KNOW it does not have
a metatable. I do notice a bit of performance gain when doing this,
mostly when I write tests which repeatedly bang on this part of the code.
My concern in all this has been that lua_setfield() would be a big
performance improvement on the pushstring(), replace(), settable()
sequence that is required to do the equivalent operation. I was assuming
that replace() is less optimal than the tricks that could be played
internally to do the equivalant thing. But I've been doing some tests
and, even when banging on it, the performance difference is negligible.
I suppose this is because the replace() is always only having to move
one item on the stack.
Anyway, once again Lua has proven to be so fast that optimizations
aren't really needed!!!
--
chris marrin ,""$,
chris@marrin.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'