Moves lua off of the timer subsystem and onto its own internal scheduler. (#82131)

## About The Pull Request
Lua uses the timer subsystem, which can end up holding the entire timer
subsystem if lua is creating a lot of timers.
The solution to this is to use an internal scheduler instead so that the
load gets placed onto the lua subsystem.

## Why It's Good For The Game
Performance improvement when using lua scripts.

## Changelog
🆑
refactor: Auxlua no longer uses the timer subsystem to get stuff done,
lua scripts shouldn't slow down timers anymore.
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
This commit is contained in:
Watermelon914
2024-03-21 21:59:16 +00:00
committed by GitHub
parent d136c3786c
commit fe3c2edddd
5 changed files with 328 additions and 246 deletions
+9
View File
@@ -16,6 +16,7 @@ SUBSYSTEM_DEF(lua)
var/list/resumes = list()
var/list/current_run = list()
var/list/current_states_run = list()
/// Protects return values from getting GCed before getting converted to lua values
/// Gets cleared every tick.
@@ -97,6 +98,7 @@ SUBSYSTEM_DEF(lua)
// then resumes every yielded task in the order their resumes were queued
if(!resumed)
current_run = list("sleeps" = sleeps.Copy(), "resumes" = resumes.Copy())
current_states_run = states.Copy()
sleeps.Cut()
resumes.Cut()
@@ -136,6 +138,13 @@ SUBSYSTEM_DEF(lua)
if(MC_TICK_CHECK)
break
while(length(current_states_run))
var/datum/lua_state/state = current_states_run[current_states_run.len]
current_states_run.len--
state.process(wait)
if(MC_TICK_CHECK)
break
// Update every lua editor TGUI open for each state that had a task awakened or resumed
for(var/datum/lua_state/state in affected_states)
INVOKE_ASYNC(state, TYPE_PROC_REF(/datum/lua_state, update_editors))