Efficiency of entities that have no power.

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Efficiency of entities that have no power.

Post by orzelek »

Rseding91 wrote:
Optera wrote:
Rseding91 wrote:
Optera wrote:What would be the most CPU friendly way to manage 1k+ beacons?
  • Have them on all the time?
    Requires more power producing entities.
  • Use inserters to remove the modules on circuit condition?
    Adds at least 2 inserters per beacon for another 2k entities.
  • Switch them off with power switches?
    "one of the worse ways you can stop a factory", but it doesn't add a lot of extra entities.
Leave them fully powered at all times. Solar panels have zero CPU cost to exist so you can just make more of them to give power to your beacons.
What about accumulators? I doubt calculating remaining charge is free.
Accumulators are grouped like solar panels are.
Out of curiosity:
When I build 100 of them each will start charging tiny bit they will get grouped in the end when they charge to full?
I looked for info about grouping in debug menu but I did not find any.

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Efficiency of entities that have no power.

Post by daniel34 »

orzelek wrote:Out of curiosity:
When I build 100 of them each will start charging tiny bit they will get grouped in the end when they charge to full?
I can't speak for Rseding91 or the devs, but afaik that is the case, accumulators that reach full charge will group together.

Otherwise grouping would make no sense, the player (or robots) are not able to place accumulators at the same tick; in the future they would all be processed individually if there wasn't a mechanism that groups them together once they reach the same level (empty or full*).

* This is a simplified explanation, they might also group together if they have the exact same accumulator level, however that happens (i'm only speculating here)
quick links: log file | graphical issues | wiki

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Efficiency of entities that have no power.

Post by Rseding91 »

orzelek wrote:Out of curiosity:
When I build 100 of them each will start charging tiny bit they will get grouped in the end when they charge to full?
I looked for info about grouping in debug menu but I did not find any.
They get grouped when the energy level of a given group ends up matching that of any other group. So unless you try *really* hard to keep multiple accumulators at different levels they will eventually group as they charge fully or deplete fully.
If you want to get ahold of me I'm almost always on Discord.

Xeteth
Fast Inserter
Fast Inserter
Posts: 158
Joined: Tue Feb 17, 2015 6:06 am
Contact:

Re: Efficiency of entities that have no power.

Post by Xeteth »

Rseding91 wrote:"Powering down" things is one of the worse ways you can stop a factory. Simply not giving it any resources to consume/use is the ideal way.

The problem is: "powering down" an entity means the normal update logic on the entity can't run because there's no power to do things like "move the inserter arm". The entity has no update notification when power is restored so it can't disable itself.

Adding such a notification would be a gigantic waste of CPU time because 99% + of the time the entity has power or will have power next tick.
Rseding91 wrote:Making beacons switch off on signals would be the exact same as switching off through loss of power. It wouldn't save any additional UPS.

Circuit "switch off" is just a flag in the entity that forces it to not run the normal update logic. It's also one of the worse ways to "power down" something.
Would you be able to explain what's going on in this particular gif?

Image

You'll notice that when the power is on all the entities are active (to be expected), then the inserters are stopped via circuit logic, power is removed and finally the inserters are given the signal to be turned on again.

This actually reduces the number of active entities for some reason.

It's probably completely intended to work this way - I'm just wondering if we could possibly exploit this for minuscule performance increases (and it seems interesting to me).

Cheers!

EditorRUS
Fast Inserter
Fast Inserter
Posts: 118
Joined: Sat Feb 23, 2013 10:32 pm
Contact:

Re: Efficiency of entities that have no power.

Post by EditorRUS »

I don't get this one thing: how exactly do entities in this game work?

Do you use some kind of gigantic list with all machinery and simply iterate through it each tick? If so, then holy crap is this inefficient.
Some kind of event-driven state-based system would be so much better than this.
Needless explanation

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Efficiency of entities that have no power.

Post by Rseding91 »

EditorRUS wrote:I don't get this one thing: how exactly do entities in this game work?

Do you use some kind of gigantic list with all machinery and simply iterate through it each tick? If so, then holy crap is this inefficient.
Some kind of event-driven state-based system would be so much better than this.
Needless explanation
No, entities that are active are maintained in a list of active entities. When they decide they don't need to do work anymore (assembling machine output is full and wants to output a recipe) it deactivates itself and is removed from the active entities list. When inactive (red circle in debug) it takes zero CPU time and is not touched. When something like an inserter pulls from the machine it wakes it up if it was sleeping because it had to many items in the output and so on.

The same with belts/inserters/most things.
If you want to get ahold of me I'm almost always on Discord.

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

Rseding91 wrote:
EditorRUS wrote:I don't get this one thing: how exactly do entities in this game work?
Do you use some kind of gigantic list with all machinery and simply iterate through it each tick? If so, then holy crap is this inefficient.
Some kind of event-driven state-based system would be so much better than this.
Needless explanation
No, entities that are active are maintained in a list of active entities. When they decide they don't need to do work anymore (assembling machine output is full and wants to output a recipe) it deactivates itself and is removed from the active entities list. When inactive (red circle in debug) it takes zero CPU time and is not touched. When something like an inserter pulls from the machine it wakes it up if it was sleeping because it had to many items in the output and so on.
The same with belts/inserters/most things.
How does this apply to combinators and other cirquit triggered components?

At first I thought as long as the components do not receive/process a state-change they will be idle. Using near 0% CPU. But I have to re-adjust my thoughts when my UPS is 15-20 at best and entity update is always between 30 and 40 after building close to 150k combinators, which is only a small part of my intended build for a massive memory cell, that I have only connected to the electric network at this point. It is not even being used yet.

This is a schematic that I have found somewhere(reddit? I did not bookmark the original post :( ) that I used as a building block for my design, I'm using the 5 gates per cell variant.
https://i.imgur.com/WcbiO3y.png

I have about 30k cells currently of the intended ~500k but I stopped building as this is just pointless when it breaks my UPS like this. According to debug there are between 450 and 480 active entities in each chunk that holds combinators while each of those are literally doing nothing.

EDIT:
btw, I'm playing on 0.15 , would 0.16 offer me any increase in performance in this regard?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Efficiency of entities that have no power.

Post by Rseding91 »

wak wrote:
Rseding91 wrote:
EditorRUS wrote:I don't get this one thing: how exactly do entities in this game work?
Do you use some kind of gigantic list with all machinery and simply iterate through it each tick? If so, then holy crap is this inefficient.
Some kind of event-driven state-based system would be so much better than this.
Needless explanation
No, entities that are active are maintained in a list of active entities. When they decide they don't need to do work anymore (assembling machine output is full and wants to output a recipe) it deactivates itself and is removed from the active entities list. When inactive (red circle in debug) it takes zero CPU time and is not touched. When something like an inserter pulls from the machine it wakes it up if it was sleeping because it had to many items in the output and so on.
The same with belts/inserters/most things.
How does this apply to combinators and other cirquit triggered components?

At first I thought as long as the components do not receive/process a state-change they will be idle. Using near 0% CPU. But I have to re-adjust my thoughts when my UPS is 15-20 at best and entity update is always between 30 and 40 after building close to 150k combinators, which is only a small part of my intended build for a massive memory cell, that I have only connected to the electric network at this point. It is not even being used yet.

This is a schematic that I have found somewhere(reddit? I did not bookmark the original post :( ) that I used as a building block for my design, I'm using the 5 gates per cell variant.
https://i.imgur.com/WcbiO3y.png

I have about 30k cells currently of the intended ~500k but I stopped building as this is just pointless when it breaks my UPS like this. According to debug there are between 450 and 480 active entities in each chunk that holds combinators while each of those are literally doing nothing.

EDIT:
btw, I'm playing on 0.15 , would 0.16 offer me any increase in performance in this regard?
Can you give me a copy of the save you're using? I can profile it and see what's going on. Most circuit logic only updates when the state changes (chests for example) but some combinator logic still has to do extra work.
If you want to get ahold of me I'm almost always on Discord.

bobucles
Smart Inserter
Smart Inserter
Posts: 1669
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Efficiency of entities that have no power.

Post by bobucles »

I have about 30k cells currently of the intended ~500k but I stopped building as this is just pointless when it breaks my UPS like this.
Factorio: FPGA simulator :lol:

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

Can you give me a copy of the save you're using? I can profile it and see what's going on. Most circuit logic only updates when the state changes (chests for example) but some combinator logic still has to do extra work.
Yes I can. I appreciate that you want to take a look at this.

How do I provide my save to you?
The save itself is about 420MB in size and I'm using a "couple" mods in there, it also includes some mods made by other people that I have tweaked, edited or expanded for the purpose of private use. Would you prefer a package containing all of the files involved or perhaps a minimalized reproduction of the issue in a vanilla save?

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

I had to google FPGA, but yeah thats what it comes down to

I have the feeling an FPGA is a bit more though

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Efficiency of entities that have no power.

Post by Rseding91 »

wak wrote:
Can you give me a copy of the save you're using? I can profile it and see what's going on. Most circuit logic only updates when the state changes (chests for example) but some combinator logic still has to do extra work.
Yes I can. I appreciate that you want to take a look at this.

How do I provide my save to you?
The save itself is about 420MB in size and I'm using a "couple" mods in there, it also includes some mods made by other people that I have tweaked, edited or expanded for the purpose of private use. Would you prefer a package containing all of the files involved or perhaps a minimalized reproduction of the issue in a vanilla save?
Dropbox/google drive?
If you want to get ahold of me I'm almost always on Discord.

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

Rseding91 wrote:Dropbox/google drive?
I put it on google drive. To which address can I send the invite?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Efficiency of entities that have no power.

Post by Rseding91 »

wak wrote:
Rseding91 wrote:Dropbox/google drive?
I put it on google drive. To which address can I send the invite?
You should be able to make it public and put a link here? I haven't actually used google drive just dropbox so I'm not sure how google drive works.
If you want to get ahold of me I'm almost always on Discord.

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

Rseding91 wrote:You should be able to make it public and put a link here? I haven't actually used google drive just dropbox so I'm not sure how google drive works.
Thats the thing, I prefer not making it public. Anything beyond google drive I would have to create or setup as well. The mods contain raw edits and updates which may or may not conflict with published mods and I don't want to be the guy that causes trouble for any of the original creators nor claim any of their works as my own.

Do you have another solution perhaps like an upload-only ftp ? Otherwise I will put it to public for the duration of your download and send you the link in PM

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Efficiency of entities that have no power.

Post by orzelek »

wak wrote:
Rseding91 wrote:You should be able to make it public and put a link here? I haven't actually used google drive just dropbox so I'm not sure how google drive works.
Thats the thing, I prefer not making it public. Anything beyond google drive I would have to create or setup as well. The mods contain raw edits and updates which may or may not conflict with published mods and I don't want to be the guy that causes trouble for any of the original creators nor claim any of their works as my own.

Do you have another solution perhaps like an upload-only ftp ? Otherwise I will put it to public for the duration of your download and send you the link in PM
I think that there might be an option to make it semi-private. I'm not sure about google drive but I seen in few places option where files are available for anyone that has the link but not searchable etc.

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Efficiency of entities that have no power.

Post by Aeternus »

Rseding91 wrote:
Optera wrote:
Rseding91 wrote:"Powering down" things is one of the worse ways you can stop a factory. Simply not giving it any resources to consume/use is the ideal way.

The problem is: "powering down" an entity means the normal update logic on the entity can't run because there's no power to do things like "move the inserter arm". The entity has no update notification when power is restored so it can't disable itself.
Another reason for making beacons switch on/off on signals. Sadly switching beacons wasn't voted higher in circuit feature poll.
Currently you have to decide between draining power for more UPS or switch power off at the expense of continuous "needless" UPS updates. Placing an inserter loop, removing/inserting modules on signals, next to every beacon simply takes too much space to be a feasible alternative.
Making beacons switch off on signals would be the exact same as switching off through loss of power. It wouldn't save any additional UPS.

Circuit "switch off" is just a flag in the entity that forces it to not run the normal update logic. It's also one of the worse ways to "power down" something.
Might be a thought to change the logic for the beacons then. Instead of consuming half a megawatt themselves, maybe make them add 10% power consumption to each effect receiver instead, then drop the beacon "drain" to 80KW? That way when you idle a beaconed part of your factory you're not either forced to use a power switch or waste several MW of power for basically nothing. Not every part of your factory operates continuously after all.
It'll also make the "Green Beacon" an option, 80% power reduction to all receivers and not such a power consumption that the beacon itself offsets all power savings in the effect receivers.

wak
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Mar 19, 2018 7:53 pm
Contact:

Re: Efficiency of entities that have no power.

Post by wak »

orzelek wrote:I think that there might be an option to make it semi-private. I'm not sure about google drive but I seen in few places option where files are available for anyone that has the link but not searchable etc.
This is exactly how google deals with this. I have 3 choices, full public searchable by searchengines, just the share link you mentioned, anyone with the link can use it, or i can send someone a private invite through email which is only accessible by 1 person only. I guess the share link seems a good alternative without too much effort or risk. Thnx for thinking along!

Post Reply

Return to “Ideas and Suggestions”