Missing Items Circuit


This is a very simple mod that adds a special combinator that outputs the items of all ghosts in the logistics network it is placed in.

Content
2 years ago
0.16 - 1.1
961
Logistic network

i Performance issues

6 years ago

First of all, this mod has only been out for an hour, and I already love it. I assumed this feature was in the vanilla game, but when I went to use it, I found it wasn't.

That said, as this is implemented at the moment, it is far too slow in terms of performance. With a single combinator placed, my game now pauses for approx. half a second every 10 seconds (which is how often the combinators update), and i'm still in mid-game. I'm inexperienced making factorio mods, but wouldn't it be possible to update the combinators when a ghost is placed, instead of searching for every ghost in the map every 10 seconds?
Alternatively, do one iteration of the main loop every frame to spread the work over multiple frames.

A couple of suggestions:

A new combinator which outputs all of the logistics requests in a network. So if I had requester chests with a request of 500 ammo, and another requester chest with 50 circuits, it would output 500 ammo and 50 circuits. It would save me from having to put the request in the requester chest and then adding it to the requester circuit for the train station as well (LTN). Possible also add requests from buffer chests, although I could see arguments for and against it. Perhaps a toggle via the combinators enable button? Or as a separate combinator?

Give it a unique texture. Just color-shifting the combinator to another color would be fine. I can't see it taking more than 20 minutes.

Again, great concept, just needs performance improvements and it'll be on my must-have list.

6 years ago
(updated 6 years ago)

Thanks for your comments
How many ghosts do you have placed? I don't notice anything any slowdown at all in my game.
As for updating when placing ghosts I am afraid that would make it worse, as you also need to update whenever a ghost is placed, which will happen in rapid succession, and from what I read updating the circuit network in lua is quite slow, so I tried to keep those down. I can add an option to change the update rate of the combinator.

6 years ago
(updated 6 years ago)

The pauses happen when I have no ghosts at all (that I am aware of). I do have ~8 seperated logistics networks (one per base/outpost), and im playing with a large mod list (although no large mods, lots of little ones). My map is fairly large as well, although I can't measure it.
Edit: Oh, I have a mod which makes trees spread, so basically every chunk is full of trees. Perhaps that is the cause?
Perhaps you could store each ghost into an array as it is placed, and then only update the circuit network a couple of seconds after the last placed ghost. That way it shouldn't be any slower, and won't have difficulty with blueprints.

6 years ago

Can you try disabling the mod to confirm it is really the source?
I have a similar number of networks running, and placed 1k+ entity blueprints without noticing any stuttering of the game, so I am quite surprised to see that it is such an issue on your game.

6 years ago
(updated 6 years ago)

Yeah, with the mod disabled there's no pausing. I used the debug option to show how much processing time each mod is using, and it was clearly the culprit.
After some educated guesses and experimenting, I've found that find_entities_filtered is the cause of the lag. My guess is that it loops through all the entities in the surface, and since my game is massively populated with trees, it takes a while.
The code I used to confirm this was "/c for i = 0, 10 do local t = game.surfaces[1].find_entities_filtered({type="tile-ghost"}) end". With just one call to find_entities_filtered, it was hard to notice any significant lag, but with ~10 calls it paused for almost a whole second. There was no notable difference between using "tile-ghost" or "entity-ghost" as a filter.

I'm doing further testing on a new creative save by cranking up tree reproduction to see how it affects the processing time.
Edit: The test supports my theory. As more trees grew, your mod used more processing time. I scanned a large area using a radar, combined with the Big Brother mod to increase its radius. Then, using Noxy's trees for tree reproduction, I basically maxed out all of the tree reproduction config settings, periodically disabling it to see how the tree count affected the lag.

6 years ago

I'm encountering no delay but the delay that you have described I do recognize from certain other mods (that I disabled till fixed).

6 years ago

I'm seeing the same issue. Larger map, large base. Added the mod, haven't even placed a combinator yet. Every 10 seconds, my script update time goes to 5.0 and its missing-circuit.

6 years ago

Hey Whitecold,

I found your mod today and also found about performance issues ;-)
My map has 23 seperate networks and is the revealed part is pretty big too.

I fiddled around and found that if you only do a partial find_entities_filtered with the area of each logistic network it's much better performance wise.
Next step would probably be to update networks/combinators each 600ths tick and the networks themself more often but just one every 60 ticks or so.

Changes:
https://gist.github.com/NochEinKamel/999e31dcf75fa673ac505c2ec9c28ccc
1. Calculate the bounding box area of each network
2. Only query that bounding box

6 years ago
(updated 6 years ago)

same here, every 10 seconds there is a lagspike with the mod-missing-circuit performance jumping to 0.4 for a second
with the changes of kamel it's constantly sitting at 0.4 but if it only updates every 10 seconds, the spike is only 0.12 (still noticable though)

New response