#electric network update using shared buffers

1 messages · Page 1 of 1 (latest)

grand path
#

Currently each electric entity has a buffer which belongs to an electric network and during the entity update the entity will consume energy from this buffer. The amount consumed depends upon the entity type, amount of work done, module effects, etc. The speed the entity operates at is based on the percent of the energy demand available in the buffer. If the entity needs 100J for the tick and the buffer only has 50J then the entity operates at half speed.

#

For most entities the buffer is sized based on the maximum energy consumed in 1 tick.

civic owl
#

this means every entity would actually need a bigger buffer if it in multiple networks, to work properly

#

that would be the way to multithread, if i understand you properly

#

(ie each entity has 1 energy buffer per network it is on, each one equal to the amount of energy it needs for a tick)

grand path
#

During the electric network update Factorio calculates the available energy in the buffers in electric generators on the network and the energy demand from electric power entities by adding the difference between buffer capacity and current charge. Then energy is distributed evenly to satisfy the energy demanded fairly

#

there is priority mechanisms for energy production and consumption but that would remain unchanged in this idea

civic owl
#

i don’t understand. you mean to split the buffer into multiple of a fraction of the capacity, or to make additional buffers all of equal capacity to the one network case?

#

ie 100J => 5 20J buffers, or to 5 100J buffers?

grand path
#

If instead each network had one buffer for each entity type (eg one for fast inserter, one for stack inserter, etc) and the buffer size was scaled by the maximum energy usage per tick like it is now times the number of entities in the network of that type then energy demand and distribution update time is significantly reduced

#

so currently if you have 10 inserters on a network and they can consume 100J per tick max (this is determined by power usage from the entity config divided by 60 ticks) you would have a network with 10 energy buffers

#

Each electric network update has to loop through all 10 buffers to determine the total demand and then distribute the available energy from generator buffers

#

With sharing buffers proposal there would be 1 buffer of 1000J used by all 10 inserters. The electric network update now only has check one buffer for all inserters of that type. If you increase the number of inserters of that type by 100X there is still only one buffer on the network just 100X larger.

#

This would mean that entities can no longer use the available energy in the buffer to determine how fast they can go because in low power scenarios the entities processed first would move at full speed and the entities at the end wouldn't move at all

#

Instead the buffer would need a new property which set each tick during the electric network update to indicate the percent of demand satisfied

#

that percent is the speed factor to apply to all entities using that buffer during the entity update instead of calculating (energyToUse / energyAvailable) for each entity

#

Suppose you had 10 basic inserters with 100J max energy usage per tick so a shared buffer of 1000J. In a scenario where the buffer starts full and 5 of the inserters move at full speed they will consume half the buffer. So the next electric update the buffer has 500J and wants 500J more to be full. In a full power scenario the full 500J is satisfied and percent satisfied is 1 but suppose there is not enough energy generation and only 400J could be distributed to the inserters' buffer. The buffer would have 900J out of 1000J but the percent satisfied would be 80% not 90%.

#

By going off the percent of demand satisfied instead of how full the buffer is at the start of the entity update this design results in the same behavior in low power scenarios where only some of the entities are active. If you used the percent of how full the buffer was at the start of the entity update it would be equivalent to the active entities stealing energy from idle entities of the same type in low power scenarios.

idle belfry
#

The buffer is network wide? So every network has 1 buffer? Or does every entity have its own buffer?

grand path
#

each network has a buffer for basic inserters, one for fast inserters, stack inserter, etc

#

it doesn't have to be one either. The network could group all basic inserters into two buffers which could be useful for their optimization around subnetworks and power switches

idle belfry
#

Hmmm it seems like the number of buffers a network has isn't very important then?

grand path
#

currently it has to be one buffer per entity which means millions of buffers for very large bases

#

compare that to having a couple hundred or maybe a thousand for highly modded games and it scales much better

#

it should also improve entity update time because there is almost always a cache miss when each entity fetches their energy buffer but if buffers are merged into a buffer per entity type per network then during the entity update the buffer will almost certainly be in L3 cache at worst

#

The update time wasted on a cache miss for the energy buffer is between 20 and 50% of the entity's total update time depending on entity type and what it did that tick