Stack Combinator

by modo_lv

An arithmetic combinator that performs stack size multiplication/division/rounding on item signals. Features signal inversion and output display, compatible with Picker Dollies and Nullius.

Content
5 months ago
1.1
17.5K
Circuit network

g [...] Performance Analysis Help

5 months ago

Hello,
First of thanks for the mod, it really helps creating vanilla-ish train systems.
I'm using the standard config, so an update every 6th tick and 100 combinator updates per update.
The average tick is 0.3-0.33 ms. Which means the actual update takes around 2ms. But the maximum tick time is around 4-6 ms, which would be 2-3 times the average.
Is this high fluctuation normal or should i be concerned about it.
I already tried playing around with the mod setting but independent what I configure, the maximum tick time is always 2-3 times more than the average.
Screenshot of the F5 Statistic here: https://imgur.com/a/cSSaqxP
This only happens every few seconds and I only realized it as my UPS is dipping below 60 for a moment and immediately goes back up.
The train path finder also acts up every now and then like in the screenshot with 30ms maximum tick time. Not sure if related. I use the stack combinator solely in train stations, so maybe, but reducing the update frequency and amount of combinators updated does not reduce the maximum tick time of the path finder, so probably not.
Is there any way I can debug/analyze this to find out what is causing this? If needed I can provide a save file.

5 months ago
(updated 5 months ago)

Just found out there is a debug mode. But it doesn't give me any log messages during runtime.

4 months ago

I'm in a pretty busy time in my life and am not playing Factorio, and I have tried to optimize the combinator performance as best as I can over the course of development, but so far it seems that nothing short of creating entire networks of hidden combinators would make much difference (see my explanation in another discussion for details).

That being said, the spike behaviour is weird and I don't remember noticing anything like that, and have no idea what might be causing it, especially if tweaking the performance settings doesn't affect it. Providing a save file would help, however I can't give any estimate of when I'll have time to return to Factorio and modding. In the meantime, if you have some programming knowledge, you could try taking a look at the mod code yourself.

4 months ago

Don't worry about it.
Can you point me to the function, which does the main part. I already had a quick look over the code when i encountered the problem but it wasn't really clear which it was.

4 months ago

Can't see anything obviously wrong with it. Except that the code goes beyond my Lua knowledge. These math operations containing boolean operators are just magic fuckery.
Will try do add some debug code which measures the execution time and when it takes too long prints the stack combinators to the chat/log which were processed. Maybe I have some messed up combinators lying around.
Maybe make a testworld and make some performance comparisons between vanilla+stack-combinator and my full modded list. As in the mod description you wrote that in your benchmark with default settings it takes around 0.5ms per update and my update takes 2ms even though i have a better CPU.

4 months ago
(updated 4 months ago)

I now did a testworld and copied one stack combinator a thousand times and let it run. Only stack-combinator + dependencies were active. Could see similar behaviour as in my save, so probably not a messed up combinator. The overall performance was a bit better than modded. Which means the more items, the worse the performance. The map access probably takes a bit longer.
I then increased the number of combinators to 10K. The maximum tick time increased to over 10ms. Which means the bad performance has something to do with the number of combinators. Maybe something loops over every single one.
With that i will stop proceeding as I don't know how to properly profile factorio mods.
My main issue is the train pathfinding anyway which is surely independent to this.

I also tested this mod: https://mods.factorio.com/mod/stack4cc. Not sure what it does. It seems to have no effect on the stack combinator itself. Maybe only change them when used inside these compact circuits. But having too many of these compact circuits completely tanked my performance. So not useful for me.