lua-users home
lua-l archive

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


>Yes, I'd been meaning to post something to the list about that. Thanks
>for mentioning it for me. :)
Np

>Yes, Mike Pall and I tried an implementation of this some years ago.
>However, there are several problems. The most serious is that it
>breaks the promise of the Lua API, which is that the address of a
>string as returned by lua_tolstring() remain constant while the string
>is on the stack. The stack can be reallocated by lua_checkstack(), so
>it is very difficult to maintain that guarantee. (Also, some extension
>modules assume a strong guarantee, which is that the address of the
>string remain constant while it is referenced from anywhere. This
>guarantee is not made by the API, but it has historically worked.)

Drats, I'd never thought of that. I can see that would prevent it from being a 
useful patch to many people. Will have to keep an eye out of that in my own apping 
if I keep the mod #defd in. Thanks for the heads up.

>There probably would have been a way to deal with this but the test
>implementation (which I believe is still available on the wiki) did
>not indicate that there was much speedup. Basically, interning a new
>string takes very little time, and there is some cost to the short
>string implementation, most notably the fact that the hash needs
>to be calculated on every use rather than being stored in the
>string object; even using a fast hash algorithm, the slowdown
>is noticeable. On some programs there was a speedup; on others
>a slowdown, but on the whole the results were neutral.
>
>In light of the problem mentioned above, we decided to abandon
>the experiment.
>)

I agree, it takes a trivial loop of Jit code to really register any speedup, at the 
cost of greatly increasing string complexity. I haven't found the hashing to be 
measurably slower (I precalculate and inline the hash in jit - which is cheating 
=) - it's still a lot simpler an algorithm then what is used for numbers/pointers, 
but I think the moral to the story is really that lua strings are fast.

Quick question about SpeedingUpStrings, how do you interpret the results? Am I 
reading it right that reusing a prestring gives you a 4x increase in large string 
writes?