Improve bad performance of setting constant combinator slots

MagmaMcFry
Inserter
Inserter
Posts: 37
Joined: Sun Jul 17, 2016 9:05 pm
Contact:

Improve bad performance of setting constant combinator slots

Post 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?
I don't visit the forum very often. If you want to contact me, message me on the mod portal for Factorissimo-related things, or on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Improve bad performance of setting constant combinator slots

Post 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.
If you want to get ahold of me I'm almost always on Discord.
MagmaMcFry
Inserter
Inserter
Posts: 37
Joined: Sun Jul 17, 2016 9:05 pm
Contact:

Re: Improve bad performance of setting constant combinator slots

Post 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.
I don't visit the forum very often. If you want to contact me, message me on the mod portal for Factorissimo-related things, or on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Improve bad performance of setting constant combinator slots

Post 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.
If you want to get ahold of me I'm almost always on Discord.
MagmaMcFry
Inserter
Inserter
Posts: 37
Joined: Sun Jul 17, 2016 9:05 pm
Contact:

Re: Improve bad performance of setting constant combinator slots

Post by MagmaMcFry »

Well okay then. Guess I'll have to add some performance warnings. Thanks for the response!
I don't visit the forum very often. If you want to contact me, message me on the mod portal for Factorissimo-related things, or on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Improve bad performance of setting constant combinator slots

Post 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).
If you want to get ahold of me I'm almost always on Discord.
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 302
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: Improve bad performance of setting constant combinator slots

Post 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!
Post Reply

Return to “Implemented mod requests”