lua-users home
lua-l archive

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



On 17-May-05, at 8:57 AM, Rici Lake wrote:


 And I bet there are a few more pitfalls.

Possibly. But it might still be worth it.

One of the pitfalls of "short strings" is that it would require a change in the way the lexer recognises reserved words. (All reserved words are short.) Currently, the lexer uses an otherwise unused byte in the string structure which holds the token type for the reserved word; this avoids a lookup in a reserved word hash table (or direct recognition of the reserved words through a state machine.) On the other hand, the tokens read by the lexer have to be hashed into the string intern table, so it's not actually avoiding a hash lookup altogether; simply avoiding a second one. Since short strings would never need to be hashed into the string intern table, this would not necessarily be slower.

One of the big gains, on the assumption that Lua workspaces are full of short strings (many of mine are, for example), would be reduced load on the garbage collector. A short string would not even have to be marked, and would not require either malloc()ing or free()ing. I think this alone may be enough of a win to make it worthwhile. But we'd never know unless someone tried it.