lua-users home
lua-l archive

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


Hi

I am trying to develop an IDE for Luxinia, a 3D engine that is using lua for
pretty much anything (http://www.luxinia.de). Performance is a critical key
here, but lua does a good job on that.

However, debugging the luacode is not very joyful at the moment. I am testing
here a project which is using quite alot of luacode and I have an average
performance of about 280 FPS without debugging. If I switch on the hookfunction
in "cr" mode (called on lua function calls / returns), I get about 200-240 fps,
so no real loss. 
But if I try to find out which file is currently in use I fall to 1-2 fps (using
debug.getinfo). After optimizing parts of it, it raised to 7-8 fps. Then I had
the idea to let the hook function retrieve the filename as third argument.
Well, this works better - 30-40 fps. But still pretty bad compared to the
original performance (about 10%). I added an optional argument that limits
calling the hookfunction only if the file of execution seems to have changed.

I copied pieces of code from the ldebug.c file in my project and the way I am
retrieving the filename looks like this right now:

//lua_getstack(L, 1, ar); 
    ar->i_ci =  L->ci-1-L->base_ci; // instead of above - bad idea?
    if (ar->i_ci != 0)
    {
		CallInfo *ci = NULL;
		Closure *cl = NULL;
		ci = L->base_ci + ar->i_ci;
		lua_assert(ttisfunction(ci->func));
		cl = clvalue(ci->func);
		if (cl->c.isC) {
			lua_pushnil(L);
		}
		else {
			const char * src = getstr(cl->l.p->source);
			if (*src=='@') {
				filechange = cl->l.p->source->tsv.hash!=hookfile; // new file?
				hookfile = cl->l.p->source->tsv.hash;

				lua_pushstring(L,src);
			}
			else
				lua_pushnil(L);

		}
	} else {
		lua_pushnil(L);
	}
// filename or nil is on stack now

This piece of code is responsible for the loss of about 120FPS - so it would be
required to be much more efficient...
I already took ripped out the essential parts from other functions instead of
calling them in order to get more performance though I am not sure if that will
break something there...

I'd be happy for any advice to make this work faster. 

The only thing I can imagine, make a list of lines that contain lists of files
they belong to - and check then only the lines that are matching...

Any suggestions?

Eike