Questions to DEVs about optimization of CPU usage

Post all other topics which do not belong to any other category.
Post Reply
quadrox
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Tue Apr 05, 2016 9:09 am
Contact:

Questions to DEVs about optimization of CPU usage

Post by quadrox »

As a programmer I am quite impressed with how this game can simulate a huge world with thousands of objects interacting with each other. We can have thousands of tiles with transport belts, each of which can contain a mixture of various resources, factories are constantly producing new items, aliens are moving about, and lots more. All of this stuff needs to be constantly updated, and yet everything runs quite smoothly.

I am wondering if everything is simulated in a "brute force" fashion, or if the developers have found a way to optimize the code so that certain calculations/updates can be skipped or simplified? I would love to hear about this.

I would also love to know how often things get refreshed internally, how threading is handled and any technical details the developers would be willing to share.

Finally I am curious as to how much effort the developers spent on optimizing things early in the development, or whether such concerns were only handled later.

I understand if you guys don't have time to respond to this, I am just really curious about how this all works.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by kovarex »

Some of the optimisation examples are mentioned here:
https://www.factorio.com/blog/post/fff-82
https://www.factorio.com/blog/post/fff-84

The game is simulated 60 updates per second. The key is to turn off anything that doesn't need to be updated (empty belts, stuck belts, inserters next to empty belts or empty chests, turrets with no enemies in sight etc. etc.)
Most of the time was spent on polishing and bug solving, so it might be something like 5% - 10% of my development time spent on optimising. There are still ways to make the performance WAY WAY better compared to how it is now, and as I enjoy this kind of work there probably will be improvements.

I always started to optimise only when we built or encountered factory that is so big, that it started to be slow, so it was iterative process. Once this happend, we found out what is the biggest performance bottleneck and optimised it. In the beginning it wasn't optimised at all as premature optimisation is the root of al evil :)

quadrox
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Tue Apr 05, 2016 9:09 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by quadrox »

Wow, thanks for the quick response :) I will read those blog posts with great interest when I get home from work later.

Again, the work you guys have done so far is simply amazing, so thanks for that as well:)

User avatar
Tev
Fast Inserter
Fast Inserter
Posts: 148
Joined: Sun Aug 02, 2015 7:42 pm
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by Tev »

kovarex wrote:There are still ways to make the performance WAY WAY better compared to how it is now, and as I enjoy this kind of work there probably will be improvements.
Omg yes.

YES!

I might start using concrete again.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by kovarex »

Tev wrote:I might start using concrete again.
What?

User avatar
Tev
Fast Inserter
Fast Inserter
Posts: 148
Joined: Sun Aug 02, 2015 7:42 pm
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by Tev »

Well . . .

Pollution decreases UPS, right? More biters, attacks, chunks calculating pollution etc.

So covering your base with concrete, especially in producitivity-heavy lategame will enlarge the pollution cloud quite a bit. Therefore less UPS. My computer already struggles around 30-45UPS in my most ambitious save where I am going to expand a lot more, so concrete is just not an option.
I could concrete "only" paths or something, but that would require larger footprint for bases, more hassle when (re)designing and it would still increase pollution slightly, so that doesn't seem like a pleasant solution.

I might be completely wrong on the scale of UPS decrease from concrete-spam (Has anyone tested this on large scale? Links pls? :) Btw that does give me an idea to try it in my base, shouldn't take more than one hour...), but I do like to optimize for UPS . . . Therefore more optimizations -> More UPS -> I might stop caring about UPS drop from concrete.

EDIT: sure, another option is not playing productivity-based factories, but eff3-based . . . That would help a lot more. And would be a lot more limiting :/

EDIT2: when I think about it, switching productivity modules for efficiency ones in miners would be best thing to do to increase UPS. So my complaint about concrete might not be the most cleverest idea. Oh, well :)

quadrox
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Tue Apr 05, 2016 9:09 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by quadrox »

Does concrete increase pollution? I hope not?!

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by Supercheese »

quadrox wrote:Does concrete increase pollution? I hope not?!
It doesn't increase pollution, but it doesn't decrease it at all -- whereas regular grass does slightly absorb some pollution.

quadrox
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Tue Apr 05, 2016 9:09 am
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by quadrox »

Supercheese wrote:
quadrox wrote:Does concrete increase pollution? I hope not?!
It doesn't increase pollution, but it doesn't decrease it at all -- whereas regular grass does slightly absorb some pollution.
Ah... I shall have to delete all the concrete from my base then, what a shame.

LazyLoneLion
Fast Inserter
Fast Inserter
Posts: 183
Joined: Sun Mar 20, 2016 11:49 pm
Contact:

Re: Questions to DEVs about optimization of CPU usage

Post by LazyLoneLion »

maybe there should be some "golf-field-grass tile" in the factorio :) Or even trees... but a grass at least. We all like to have our factories nice-looking, I suppose.

...Sure, I doubt there will be smth like that in vanilla soon. Just a dream :) And there are mods for growing trees.

Post Reply

Return to “General discussion”