Page 1 of 1

Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 10:27 am
by MagmaMcFry
Constant combinators can have their signals set through the API, like this:

Code: Select all

local control_behavior = some_constant_combinator_entity.get_or_create_control_behavior()
control_behavior.parameters = {parameters = table_of_signals}
Unfortunately a single write to control_behavior.parameters takes a whole 0.1 milliseconds per signal for some reason. This doesn't seem very optimized, so could you guys please improve performance for this?

Re: Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 2:02 pm
by Rseding91
After removing the Lua portion the code is identical to setting the signals in game using the GUI: any additional overhead is purely the cost of Lua being Lua and there's nothing I can do about that.

Additionally the cost is going to depend on the total number of slots you've defined for the combinator.

Re: Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 2:54 pm
by MagmaMcFry
I already tested that commenting out the second line makes the 0.1ms per signal go away completely, so either the majority of those 0.1ms is spent translating one single signal (two tables with four entries total) from Lua into C++ (which I sorta doubt because Lua can't be that slow), or there's something weird with the C++ routine.

Re: Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 4:02 pm
by Rseding91
MagmaMcFry wrote:I already tested that commenting out the second line makes the 0.1ms per signal go away completely, so either the majority of those 0.1ms is spent translating one single signal (two tables with four entries total) from Lua into C++ (which I sorta doubt because Lua can't be that slow), or there's something weird with the C++ routine.
Lua *is* that slow. Especially so when it comes to the creation of small strings since all strings in Lua are interned. Something you do a ton of when working with signals.

Re: Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 4:25 pm
by MagmaMcFry
Well okay then. Guess I'll have to add some performance warnings. Thanks for the response!

Re: Improve bad performance of setting constant combinator slots

Posted: Fri Mar 10, 2017 5:10 pm
by Rseding91
I can add a different method "set signal" which lets you set individual signals. If you don't plan on changing more than a few it would be faster than doing parameters = ...

The advantage being you can set 1 signal and leave the rest intact (if that's what you wanted to do).

Re: Improve bad performance of setting constant combinator slots

Posted: Thu Mar 16, 2017 5:24 pm
by justarandomgeek
Rseding91 wrote:I can add a different method "set signal" which lets you set individual signals. If you don't plan on changing more than a few it would be faster than doing parameters = ...

The advantage being you can set 1 signal and leave the rest intact (if that's what you wanted to do).
That would be useful for at least some of my mods!