Optimize idle circuit networks
Posted: Wed Apr 03, 2019 1:15 pm
When an entity is connected to the circuit network, it checks for the network's state every tick. This is fine for smaller combinator builds, but starts being a big UPS drain when connecting lots of entities to networks, especially with lamps displays and similar designs. In a lot of situations, those networks will stay idle on most ticks, meaning a lot of entity updates could be skipped.
Here's a test world with nothing except 6.4k lamps connected in pairs with the condition "everything = 0" (i.e. always active)

Despite the networks being completely idle, the setup still uses up 0.5ms on my mid-range PC.
I don't know how the circuit networks functions on the code side, and I know this would be a low priority change at best, but I'd like to suggest a change in how entities read the state from the circuit network:
If the network's state doesn't change from tick to tick, then the state of all the reading entities won't change either. Which means that you can have reading entities sleep, and have the network wake up connected entities when its state changes. This way, only the network needs to be checked for updates every tick rather than each entity.
Here's a test world with nothing except 6.4k lamps connected in pairs with the condition "everything = 0" (i.e. always active)

Despite the networks being completely idle, the setup still uses up 0.5ms on my mid-range PC.
I don't know how the circuit networks functions on the code side, and I know this would be a low priority change at best, but I'd like to suggest a change in how entities read the state from the circuit network:
If the network's state doesn't change from tick to tick, then the state of all the reading entities won't change either. Which means that you can have reading entities sleep, and have the network wake up connected entities when its state changes. This way, only the network needs to be checked for updates every tick rather than each entity.