[0.16.51] Stationary cars do not sleep
Posted: Tue Jul 10, 2018 10:30 pm
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.
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.