lua-users home
lua-l archive

Re: Oh, well, looks like atoms are not possible

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


Rici Lake wrote:
...
I did 3 tests. I loaded the strings, got back their char* pointers, then put them into the registry and popped them. Then I forced a GC and loaded the strings in the registry onto the stack and checked their addresses. They matched. Then I loaded those same strings again with new pushstring() calls, and they matched. Then I executed these two functions, in turn:
function _getabc()
 return "abc"
end
function _getlongString()
 return "AVeryVeryVeryVeryVeryVeryLongString"
end
Looking at the returned string values, the first one matched and the second one didn't.
As far as I know, that can only mean that either the long string got gc'd somewhere along the way, or that you mistyped it in the _getlongString function.
OK, thanks for making me go back to look. It was a stupid coding error on my part! They are all the same. So that's great. Now I've done a timing test between pushstring and rawgeti to push a string. I also tested pushlstring() to factor out the strlen() operation. I did 10 million iterations of pushstring(), pushlstring(), and rawgeti(). The results are:
 short string long string
 ------------ -----------
pushstring() 2.9 sec 4.1 sec
pushlstring() 2.2 sec 3.3 sec
rawgeti() 3.1 sec 3.1 sec
So, hashing short strings that already exist is faster than rawgeti()! Since I expect most property strings to be shorter than 35 chars, I won't bother with doing rawgeti(). But I will still make an Atom class which will cache strings and their lengths and then allow those strings to pushed and compared.
I tried hacking this up in my app and saw a 50% improvement in performance!
Anyway, I can post the results if anyone is interested.
Thanks for the help...
--
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$$b1ドル" |$$ ,` ,$$" ``' $$
 ```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'

AltStyle によって変換されたページ (->オリジナル) /