Xman1109 / Atomic_Overhaul

https://mods.factorio.com/mod/Atomic_Overhaul/downloads
Other
7 stars 5 forks source link

Performance suggestion with the new Heat Accumulator mechanic #42

Closed AmCh-Q closed 6 months ago

AmCh-Q commented 11 months ago

While playing today, I noticed a large lag spike every 10 seconds and traced it down to the script.on_nth_tick for Heat Accumulators. I was going to submit a bug report, and only then did I notice the mod setting disabling that, so I presume that is a known issue. In my save game it was causing a ~140ms script update when the rest of my loaded mods cost 1-2ms combined.

My suggestion is that instead of scanning all surfaces on_nth_tick, it might be much more UPS-friendly to keep a list of all unfilled heat accumulators in the global table. This list may be updated by on_built_entity, on_robot_built_entity, and on_entity_cloned, so scanning all surfaces is only needed during on_configuration_changed. Then only that list needs to be scanned on_nth_tick to check if any have been filled.

AmCh-Q commented 11 months ago

I just saw the closed https://github.com/Xman1109/Atomic_Overhaul/issues/40#issue-1806106049 so now I know that this performance issue has been known for a while. Still I think avoiding scanning all entities would likely (mostly) solve this issue (until a player builds a massive number of unfilled heat accumulators).