tweak lua gc

lua C++ bindings require ~400KB worth of tables now; so bump memory
available to rt-safe scripts (full interpreter) to 2MB.

Also switch to incremental GC.
This commit is contained in:
Robin Gareus 2016-07-06 03:32:08 +02:00
parent aee63fe5a3
commit a2f249d1d7
4 changed files with 21 additions and 4 deletions

View File

@ -46,7 +46,7 @@ LuaProc::LuaProc (AudioEngine& engine,
Session& session,
const std::string &script)
: Plugin (engine, session)
, _mempool ("LuaProc", 1048576) // 1 MB is plenty. (64K would be enough)
, _mempool ("LuaProc", 2097152)
, lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
, _lua_dsp (0)
, _script (script)
@ -69,7 +69,7 @@ LuaProc::LuaProc (AudioEngine& engine,
LuaProc::LuaProc (const LuaProc &other)
: Plugin (other)
, _mempool ("LuaProc", 1048576) // 1 MB is plenty. (64K would be enough)
, _mempool ("LuaProc", 2097152)
, lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
, _lua_dsp (0)
, _script (other.script ())
@ -118,6 +118,7 @@ LuaProc::init ()
_stats_avg[0] = _stats_avg[1] = _stats_max[0] = _stats_max[1] = _stats_cnt = 0;
#endif
lua.tweak_rt_gc ();
lua.Print.connect (sigc::mem_fun (*this, &LuaProc::lua_print));
// register session object
lua_State* L = lua.getState ();
@ -759,7 +760,8 @@ LuaProc::connect_and_run (BufferSet& bufs,
#ifdef WITH_LUAPROC_STATS
int64_t t1 = g_get_monotonic_time ();
#endif
lua.collect_garbage (); // rt-safe, slight *regular* performance overhead
lua.collect_garbage_step ();
#ifdef WITH_LUAPROC_STATS
++_stats_cnt;
int64_t t2 = g_get_monotonic_time ();

View File

@ -238,7 +238,7 @@ Session::Session (AudioEngine &eng,
, pending_locate_flush (false)
, pending_abort (false)
, pending_auto_loop (false)
, _mempool ("Session", 1048576)
, _mempool ("Session", 2097152)
, lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
, _n_lua_scripts (0)
, _butler (new Butler (*this))
@ -5170,6 +5170,7 @@ Session::try_run_lua (pframes_t nframes)
Glib::Threads::Mutex::Lock tm (lua_lock, Glib::Threads::TRY_LOCK);
if (tm.locked ()) {
try { (*_lua_run)(nframes); } catch (luabridge::LuaException const& e) { }
lua.collect_garbage_step ();
}
}
@ -5179,6 +5180,7 @@ Session::setup_lua ()
#ifndef NDEBUG
lua.Print.connect (&_lua_print);
#endif
lua.tweak_rt_gc ();
lua.do_command (
"function ArdourSession ()"
" local self = { scripts = {}, instances = {} }"

View File

@ -34,6 +34,8 @@ public:
int do_command (std::string);
int do_file (std::string);
void collect_garbage ();
void collect_garbage_step ();
void tweak_rt_gc ();
sigc::signal<void,std::string> Print;

View File

@ -76,6 +76,17 @@ LuaState::collect_garbage () {
lua_gc (L, LUA_GCCOLLECT, 0);
}
void
LuaState::collect_garbage_step () {
lua_gc (L, LUA_GCSTEP, 0);
}
void
LuaState::tweak_rt_gc () {
//lua_gc (L, LUA_GCSETPAUSE, 20);
lua_gc (L, LUA_GCSETSTEPMUL, 100);
}
void
LuaState::print (std::string text) {
Print (text); /* EMIT SIGNAL */