From a2f249d1d7a14498f9b1c0b46f89be4a7e611c37 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 6 Jul 2016 03:32:08 +0200 Subject: 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. --- libs/ardour/luaproc.cc | 8 +++++--- libs/ardour/session.cc | 4 +++- libs/lua/lua/luastate.h | 2 ++ libs/lua/luastate.cc | 11 +++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) (limited to 'libs') diff --git a/libs/ardour/luaproc.cc b/libs/ardour/luaproc.cc index 03deea7114..3e7a01a399 100644 --- a/libs/ardour/luaproc.cc +++ b/libs/ardour/luaproc.cc @@ -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 (); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 33d8b08832..677aca249e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -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 = {} }" diff --git a/libs/lua/lua/luastate.h b/libs/lua/lua/luastate.h index 88ffc93486..5a5c939c2a 100644 --- a/libs/lua/lua/luastate.h +++ b/libs/lua/lua/luastate.h @@ -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 Print; diff --git a/libs/lua/luastate.cc b/libs/lua/luastate.cc index 546b02a006..3b8a7ae25a 100644 --- a/libs/lua/luastate.cc +++ b/libs/lua/luastate.cc @@ -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 */ -- cgit v1.2.3