perf(runtime): open only the stdlib libraries the Lua sources use
io, coroutine, utf8 and debug have zero call sites across every module and app, and each one's tables and closures are live heap in every app's state. Selective luaL_requiref replaces luaL_openlibs; os stays for one os.date. Measured in the emulator: VM+stdlib baseline 24.4kB -> 21.3kB live.
This commit is contained in:
@@ -65,7 +65,19 @@ bool Runtime::open() {
|
||||
if (!state_)
|
||||
return false;
|
||||
*static_cast<Runtime**>(lua_getextraspace(state_)) = this;
|
||||
luaL_openlibs(state_);
|
||||
// Only the libraries the Lua sources here actually reference. io, coroutine,
|
||||
// utf8 and debug have zero call sites across every module and app, and each
|
||||
// one's tables and closures are live heap in every app's state.
|
||||
static const luaL_Reg kLibs[] = {
|
||||
{LUA_GNAME, luaopen_base}, {LUA_LOADLIBNAME, luaopen_package},
|
||||
{LUA_TABLIBNAME, luaopen_table}, {LUA_STRLIBNAME, luaopen_string},
|
||||
{LUA_MATHLIBNAME, luaopen_math}, {LUA_OSLIBNAME, luaopen_os},
|
||||
{nullptr, nullptr},
|
||||
};
|
||||
for (const luaL_Reg* lib = kLibs; lib->func; lib++) {
|
||||
luaL_requiref(state_, lib->name, lib->func, 1);
|
||||
lua_pop(state_, 1);
|
||||
}
|
||||
|
||||
// Primary Namespaces
|
||||
bindings::registerBle(state_);
|
||||
|
||||
Reference in New Issue
Block a user