tweak lua gc
authorRobin Gareus <robin@gareus.org>
Wed, 6 Jul 2016 01:32:08 +0000 (03:32 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 6 Jul 2016 01:32:08 +0000 (03:32 +0200)
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
libs/ardour/session.cc
libs/lua/lua/luastate.h
libs/lua/luastate.cc

index 03deea7114980c9fa1ef178a129e2c44138f24c1..3e7a01a39989bb226d7d7e587b03d6fcdedd9cce 100644 (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 ();
index 33d8b08832d30fb0806f9cdc4dd4dad597467c2c..677aca249e01d21545492539483c130e98e8c07c 100644 (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 = {} }"
index 88ffc93486396b5eea462e58c76aba92d0f656f0..5a5c939c2ad59a7011268bc06c13fd24dea33fdd 100644 (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;
 
index 546b02a006d8afcf1aa89da1d7abf0960d7f4df7..3b8a7ae25a12de20846f764f35c98d1e80b61cfb 100644 (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 */