[0.16.51] Stationary cars do not sleep

Bugs that are actually features.
Post Reply
Allaizn
Former Staff
Former Staff
Posts: 90
Joined: Sat Mar 03, 2018 12:07 pm
Contact:

[0.16.51] Stationary cars do not sleep

Post by Allaizn »

Today's bug report may be no bug at all, but I don't know where else to post this, so here goes:
Many entities, like assemblers, inserters and beacons, have a "sleep" mode, where they're not actively updated anymore. This mode is made visible by the "show active state" debug option.
After a short discussion on a reddit thread presenting a 10k spm map, link, I decided to finally test how bad especially stationary cars really are, and the results are quite harsh:
Running the attached maps on my i7 8700K @ 4.7 GHz using the benchmark option shows that 10k stationary cars, no matter fueled or not, eat about 0.5ms update time, or about 55±1ns per car. These are 260ish clock cycles wasted for every car. For reference, chests only take 0.3±0.1ns, or about 2 cycles (which I'll generously call a measurement error, since the pure existence of the map takes time, too)
It doesn't sound like much, but the map linked in the reddit post contained about 10k stationary cars, and I also plan on using thousands of them in my car based 10k spm base, where every ms update time counts.

The main question is: what do cars update for? Why can't they sleep like other entities?
Cars without people inside will never move once they become stationary on a non-belt, which is easily checkable.
Cars don't use fuel, and the "no fuel" blinker is synched for all cars, so there's no need to update for that.
Everything that would change a car, like moving it, or inserting fuel requires other entities to perform some action.

All of the above of course also applies for tanks and probably all other vehicles (from mods) as well. Maybe have a lua switch that prevents sleep to allow for "smart" vehicle mods.
Attachments
car fuel test.zip
Empty map with 10 fueled cars
(1.79 MiB) Downloaded 63 times
car test.zip
Empty map with 10k fuelless cars
(1.76 MiB) Downloaded 60 times
chest test.zip
Empty map with 10k chests
(1.63 MiB) Downloaded 59 times

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

Re: [0.16.51] Stationary cars do not sleep

Post by Rseding91 »

Allaizn wrote:Today's bug report may be no bug at all.
You're correct!
If you want to get ahold of me I'm almost always on Discord.

Allaizn
Former Staff
Former Staff
Posts: 90
Joined: Sat Mar 03, 2018 12:07 pm
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Allaizn »

May I ask as to why this won't be fixed?
It seems to be an easy fix, but I of course don't know the code base :)

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

Re: [0.16.51] Stationary cars do not sleep

Post by Rseding91 »

Allaizn wrote:May I ask as to why this won't be fixed?
It seems to be an easy fix, but I of course don't know the code base :)
I don't consider it worth the code complexity when so far it hasn't been measured to be an issue. 10,000 cars at 0.5 MS is great - that's well within acceptable performance levels.

If you actually *do* anything with the cars (move them on belts) it will have way more of an impact than the cars alone do.
If you want to get ahold of me I'm almost always on Discord.

Allaizn
Former Staff
Former Staff
Posts: 90
Joined: Sat Mar 03, 2018 12:07 pm
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Allaizn »

Rseding91 wrote:10,000 cars at 0.5 MS is great - that's well within acceptable performance levels.
That's entirely my point: it's not great. It's more than 100x worse than chests, and stationary cars are basically large chests.
Currently, 0.5ms are 3% of the maximal update time of 16.67 ms. IMO it's really bad to waste that much time on doing nothing.
Rseding91 wrote:If you actually *do* anything with the cars (move them on belts) it will have way more of an impact than the cars alone do.
Car movement needs optimization anyway, but that's not the point here. It's totally acceptable for moving cars to munch on UPS.
Rseding91 wrote:I don't consider it worth the code complexity when so far it hasn't been measured to be an issue.
I consider 3% to be an issue worth fixing, since I don't expect the code change to be extremely complex (like for fluids). The sleep and awake mechanics are already well established, which means that you may be able to copy/paste them from other entities. But that's of course my opinion, and as I said, I have no idea about your code base, which means that I'll take your word on it.

The game is well optimized either way (thanks for that :D ), but the whole point of this report was to maybe optimize it even further. Now that you know about it, it's of course your decision to not do something about it (for now?). Just know that as least to people would be happy about it ;)
Last edited by Allaizn on Wed Jul 11, 2018 6:41 pm, edited 1 time in total.

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

Re: [0.16.51] Stationary cars do not sleep

Post by Rseding91 »

Allaizn wrote:That's entirely my point: it's not great. It's more than 100x worse than chests, and stationary cars are basically large chests.
Chests aren't updatable entities so they take zero CPU time. You can't get better than that. It's like saying cars take more UPS than an iron patch - well of course it does :P
If you want to get ahold of me I'm almost always on Discord.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Jap2.0 »

Rseding91 wrote:
Allaizn wrote:May I ask as to why this won't be fixed?
It seems to be an easy fix, but I of course don't know the code base :)
I don't consider it worth the code complexity when so far it hasn't been measured to be an issue. 10,000 cars at 0.5 MS is great - that's well within acceptable performance levels.

If you actually *do* anything with the cars (move them on belts) it will have way more of an impact than the cars alone do.
Actually I'm getting 1.6ms with 10,000 cars.
There are 10 types of people: those who get this joke and those who don't.

Allaizn
Former Staff
Former Staff
Posts: 90
Joined: Sat Mar 03, 2018 12:07 pm
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Allaizn »

Rseding91 wrote:You can't get better than that.
Wouldn't a sleep cycle for cars do the same? Or do I misundersttand how sleeping works?
I always thought that entities sleeping would prevent them from being updated at all.
Jap2.0 wrote: Actually I'm getting 1.6ms with 10,000 cars.
My system is on the high end of possible ones. It's therefore quite understandable that your results may be much worse.
10k cars also isn't a common use case, at least on anything but the largest bases. The map shown on reddit runs at just a little less than 60 UPS on my machine, and its 10k spm using 10k cars (according to the creator, I didn't count).
Your machine will likely not be able to handle such a base at high UPS, but scaling it down would still mean that 3% of the update time is wasted on cars doing nothing.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Jap2.0 »

Allaizn wrote:
Jap2.0 wrote: Actually I'm getting 1.6ms with 10,000 cars.
My system is on the high end of possible ones. It's therefore quite understandable that your results may be much worse.
10k cars also isn't a common use case, at least on anything but the largest bases. The map shown on reddit runs at just a little less than 60 UPS on my machine, and its 10k spm using 10k cars (according to the creator, I didn't count).
Your machine will likely not be able to handle such a base at high UPS, but scaling it down would still mean that 3% of the update time is wasted on cars doing nothing.
Yeah, I'm just pointing out that it's going to be much worse for some people with older hardware.
Last edited by Jap2.0 on Wed Jul 11, 2018 7:49 pm, edited 1 time in total.
There are 10 types of people: those who get this joke and those who don't.

Allaizn
Former Staff
Former Staff
Posts: 90
Joined: Sat Mar 03, 2018 12:07 pm
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Allaizn »

Jap2.0 wrote:and I agree, there isn't really any practical reason to have 10k cars sitting around.
That's the exact opposite of what I wanted to say. There is a practical reason for that many cars, see the map in the reddit post I linked in my first post.
My follow up basically says that you need to adjust this number for lower end systems. Let's say your PC can only handle 1k spm, than there's a reason to have 1k stationary cars, which would still eat about 3% of your performance. My system on the other hand handles 10k spm and therefore easily has 10k stationary cars on it - but it's still 3%

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: [0.16.51] Stationary cars do not sleep

Post by Jap2.0 »

Allaizn wrote:
Jap2.0 wrote:and I agree, there isn't really any practical reason to have 10k cars sitting around.
That's the exact opposite of what I wanted to say. There is a practical reason for that many cars, see the map in the reddit post I linked in my first post.
My follow up basically says that you need to adjust this number for lower end systems. Let's say your PC can only handle 1k spm, than there's a reason to have 1k stationary cars, which would still eat about 3% of your performance. My system on the other hand handles 10k spm and therefore easily has 10k stationary cars on it - but it's still 3%
Ah, nevermind. I thought that you were talking about cars on belts and stuff that wouldn't sleep, but looking at the Reddit post and thinking about this further I see how stationary cars could be very useful.
There are 10 types of people: those who get this joke and those who don't.

Post Reply

Return to “Not a bug”