[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another attempt at SpeedingUpStrings
- From: David Manura <dm.lua@...>
- Date: Sat, 22 Dec 2007 19:46:11 +0000 (UTC)
> On 12/18/07, Asko Kauppi <askok <at> dnainternet.net> wrote:
> > You can push all the strings in startup on the registry, with light
> > userdata pointers (of the C side string constant) serving as keys.
> > This will turn string pushing into a table lookup instead; maybe no
Even better, make the string constants upvalues of the C closure. Retrieve them
with lua_upvalueindex/lua_pushvalue. Similar approaches are based on moving
more code from C to Lua.
I don't see this as a major performance problem. If you have a bottleneck due
to the following function being executed a billion times:
static const char * s = "hello.......";
static bool b = true;
int get_value(lua_State * L) {
if (b) lua_pushstring(L, s);
else lua_pushnil(L);
return 1;
}
then rewrite it so that lua_pushstring is done only once at initialization time.
It does involve duplicate memory usage (in C and Lua), but that isn't usually a
concern unless one has huge strings.