Belt Balancer

by asdff45

Adds Balancer Parts, that can be put together, to balance all adjusting lanes.

Content
3 years ago
0.17 - 1.1
47.2K
Logistics

g Question about performance

3 years ago

I've had this mod for a while, but only started using it on a larger scale fairly recently. What I found was that my performance degraded very rapidly once I started passing a large amount of items through Belt Balancer stacks. I have about six or so 6/12 arrays and a large number of 3/3 and 6/6 arrays. With even just that, I'm dropping to 45 FPS. Am I using the mod wrong? Is there anything I can do to speed it up?

Looking at my statistics, Belt Balancer seems to be taking up substantially more time than all the rest of my mods combined, at least on the Lua side. I don't actually know exactly what the stats measure, but I'll list a screenshot below. Again - is there anything I can do on my end?

https://steamcommunity.com/sharedfiles/filedetails/?id=2155462310

3 years ago

Can you give me the savefile, so i can have a deeper look. The thing is, LUA compared to direct C++ is really slow and what im doing is moving a lot of items arund in LUA. Im not sure, if i can make it faster, but with your save, i can give it a try :)
You can upload your post to googledrive, mega.nz or any other platform of your choice. If you dont want to post it publicly here, you can send me the link via email: knoxfighter@asdff45.de

3 years ago

I have no issues sharing my save file publicly :) It is a bit modded-over, though not all of the mods are strictly necessary. This is a fairly large facility running a fairly large amount of resources, so there may well not be a way to improve it. I would love to help in any way I can, however, because I really, REALLY like your mod. It's enabled me to do some pretty neat stuff and I don't really think an alternative of it exists.

Save link as follows: https://www.dropbox.com/s/1vgtj3k4pguz7da/Solo%202.zip?dl=0

3 years ago

A random thought occurs to me... I'm already using Loaders (Loaders Redux, as you've likely seen). In theory, I could simply use a large chest, such as a Warehouse from one of the Warehousing mods. Load items into it, load items out of it. I use plenty of warehouses in the save file I linked you to, and they never seem to tank my performance. Is it possible to treat your Balancer like a giant chest, somehow? I saw the description and had a brief glance at the Lua. You're already binding individual Balancers together in a single structure. Is there no way to give that structure the properties of a chest? That way, the game could input items into into it and output items out of it using its own (presumably C++) implementation.

I vaguely remember there being a "modular chest" mod floating around which could create chests of arbitrary size and shape. I'm likely speaking out of my rear here, but this has been on my mind all day :)

3 years ago

Apologies for spamming you with messages like, but I was curious to run a few additional smaller-scale experiments. I had a brief look through your Lua code to get some idea of how the specific splitter objects work. I have trouble tracking variable definition in Lua since the mechanics are so implicit, but I think I have a decent idea. You seem to be mapping all belt connections to all Belt Balancer objects to the same one object, then calculating input and output for it in Lua. The on_nth_tick calculation eludes me, however, but that's good enough to test.

I mentioned the possibility of using a "fake chest" so I figured I'd try an actual fake chest via the Modular Chests mod, and I threw in a test against Compound Splitters, as well. The results are as follows:

https://steamcommunity.com/sharedfiles/filedetails/?id=2156163044

This is a small-scale experiment so the numbers are comparably small. With 11 inputs and 12 outputs, Belt Balancer is consuming ~170ms (I think that's what that's measuring), Compound Splitters ~0.065 and the others aren't showing up. Crucially, neither Modular Chests nor Loaders Redux show up in the Lua readout, I presume because both hook into core game mechanics (chests and the pre-existing but disabled Loader mechanic) meaning they don't actually use Lua at all. Or if they do, it's not showing up in the read-out.

Belt Balancers output in a particular pattern when they can't compress. In this example, it looks like 1 6 5 4 3 7 8 9 10 11 12 2 in this particular example. Rebuilding the Belt Balancer array appears to change how the outputs are staggered. This seems consistent with the on_nth_tick calculation, though I admit to not fully understanding the design behind that. Compound Splitters output in a staggered line, left-to-right, or in this case from buffer to end cap. Swapping those two items around reverses the priority. Modular Chests don't appear to have any output priority, and just output from right to left regardless of what I do. This is likely more a function of how Loaders choose their own priority.

I think the point of this exercise was to test a pet theory of mine - that some system of invisible loaders and interconnected storage could be used to approximate what Belt Balancers do. That doesn't seem to be the case. While it works mechanically, no balancing is achieved. So that's not an option. At this point, I don't think I can make any real optimisation suggestions. However, it does seem like Belt Balancer does a fairly complex calculation to determine which item is deposited to which belt. Could they perhaps be stored in some specific order and always output in that order as long as items existing the invisible buffer? Belt Balancer output order changes depending on when compression is lost, and this seems consistent with what I can see in the Lua. I think that calculation could be simplified in return for a loss of complexity of operation.

Then again, I could be entirely wrong :)

3 years ago

I have absolutely no problem with you spamming messages here :)
I still had not really time to look deeper into how to improve performance.

This is slower than the other variants, cause it has a ton more features and therefore has to be a little bit slower. The time values you see there, are measures in ms, so in your example, belt-balancer need 0.170ms. To keep at 60 fps, every mod added together should not have more than ~15ms (16.666ms is the time per frame factorio has to calculate everything (logic/graphic/mods, etc.).

You dont see the loaders and bigger chests, cause they are handled by factorio itself (those big chests are just custom entities and the loaders are the loaders factorio implements, with a new design and different hitboxes)

3 years ago

Whenever you have time is fine, no rush. If there's anything I can do to help, I'd be happy to. Thanks for confirming the time stat, as well. That makes sense. 60FPS offers 1/60 = 0.01(6)s, or 16.(6)ms. I think this is why I'm having issues in my current game. Belt Balancer is consuming 8-9ms just by itself, in addition to all the factories and inserters and balancers and so on that I don't see in the Lua readout. I suspect I can help on that front a little bit by replacing some of my hundreds of fabricators with beacons, but that's going off-topic.

Yeah, looking through the Belt Balancer code, it does A LOT. Part of that is making it convenient to use. I've been experimenting with stopgaps for the time being, and one of the ones I tried was the Compound Splitters mod. Setting those up is such a pain in the ass that it's going to get aggravating before long, if I keep using it. It also lacks the flexibility to curve that your Belt Balancers have, which I definitely miss. I don't really want to speak directly to the Lua code since I'm not entirely clear on how it works (although the prevalence of code comments REALLY helps :) ), but I do hope there's more performance to be gained. The game really got fun once I started using this mod.

3 years ago

I agree with the previous speaker
https://prnt.sc/uuuf7t
This is an new game with only belt balancers. 500 items for a performance test.
Is there anything you can do to optimize?
playing with 30UPS andd less is no fun and in my game I use about 50 balaancers, i starting to avoid the balancers where it is possible, but that is not the sense.

3 years ago

There is nothing that can be done to improve performance when a mod uses Lua to manipulate items on belts one by one. Which is what happens in this mod to achieve precise balancing.

3 years ago

I've run into the same UPS hits. I use a single vertical row of theses balancers on top of my bus with one belt exiting the stop of the vertical row to peel stuff off the main bus. Once my base hits small/medium size, I start losing UPS. I don't think it's the mod author's fault - I just think that the operations being done are so intensive that there's no way to avoid the UPS hit.

The mod itself is amazing and I love it.

New response