lua-users home
lua-l archive

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


It was thus said that the Great Mike Pall once stated:
> Sean Conner wrote:
> >   Third example was running the Lua interpreter with the "-i" option loading
> > up show.lua, then typing
> > 	dofile("default.lua")
> > 
> >   It was the third example that took six minutes.
> 
> The "-i" option loads readline which as a side-effect initializes
> the NLS locale for the current process from the environment
> variables.
> 
> This may slow down all conversions of strings to numbers, numbers
> to strings and string comparisons. Looks like it's 30x slower in
> your case.
> 
> Try os.setlocale("C") before the dofile().

  I did that.  Still took six minutes.  I even set the locale from the
command line and tried, and it took six minutes.

  I then did a quick look at the Lua interpeter (lua.c).  The Lua function
dofile() does:

	int n = lua_gettop(L);
	luaL_loadfile(L,name);
	lua_call(L,0,LUA_MULTRET);
	return lua_gettop(L) - n;

whereas the "-i" option appears to do:

	int base = lua_gettop(L) - narg
	luaL_loadfile(L,name);
	lua_pushcfunction(L, traceback); 
	lua_insert(L, base);
	lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
	lua_remove(L, base);
	
  I'm still not sure why loading a small file via the "-i" option before
loading the 80M script via dofile() takes so darned long.

  -spc