Page 1 of 1

Reduce overhead of LuaEntity::get_signals with parameter if_modified_since

Posted: Wed Apr 30, 2025 10:32 pm
by Harag
I'd like to propose the following signature change to LuaEntity::get_signals():

Code: Select all

get_signals(wire_connector_id, extra_wire_connector_id?, if_modified_since?) → array[Signal]?, MapTick
Read all signals from the selected wire connector.

Parameters

wire_connector_id :: <as before>
extra_wire_connector_id :: <as before>
if_modified_since :: MapTick? only return fresh signals if they were modified after this tick

Return values
→ array[Signal]? Current values of all signals, nil if there are no signals or if there were no modifications
MapTick the tick the signals were last modified, less than or equal to if_modified_since if there were no modifications
With this mods like LTN and Cybersyn that frequently poll signals could greatly reduce Lua garbage overhead and subsequent recalculations for idle circuit networks.
I assume this information is already present somewhere because combinators know when to recalculate, too.

If this is added, there should probably also be a property LuaCircuitNetwork::last_modified : MapTick.

My guess is adding the same to LuaEntity::get_signal() would not be a big improvement. That function already returns an int, only.

Re: Reduce overhead of LuaEntity::get_signals with parameter if_modified_since

Posted: Thu May 01, 2025 7:07 am
by Stringweasel
+1

Related: 98542

Re: Reduce overhead of LuaEntity::get_signals with parameter if_modified_since

Posted: Thu May 01, 2025 7:21 am
by The_LORD_thy_GOD
Seconded. This could save considerably Lua time in any mod that uses combinators for gathering input.