Page 1 of 1

[Optimization] Lamp performance improvement

Posted: Tue Aug 30, 2022 8:12 pm
by buggy123
TL;DR
Lamp optimization; change them to work entirely like solar panels to further reduce their performance impact, adjust visuals slightly to accomodate.



Note: This suggestion applies to normal, non-circuited lamps only. Circuited lamps can't be optimized as I am about to suggest and should remain as-is.


Why, aren't lamps already optimized ?
Yes; A few years ago, lamps got optimized as described in Friday Facts #229. This was a good change which made lamps much more performant.

Unfortunately, there is still a little performance impact. It's small, but the electric network updates can still add up when lamps are turning on/off:
Image

140,000 lamps is quite a lot. But real factories can still use enough lamps to cause noticeable lag. As a example, here's the # of lamps on a MP server where they're used only sparingly:
Image
With more consistent usage, there could be tens of thousands or more.

Given this, I think that investing a bit more effort to further optimize them would be a good idea.

How? They're already optimized very well.
As is, yes, they can't really be improved further without creating a disconnect between visuals and gameplay. If you remove the connection between visual appearance and the actual power consumption, a observant player would notice the discrepancy while watching the power graph at nightfall. This would be a problem even if you made the power consumption gradually increase or similar.

And it wouldn't be good to remove the staggered lighting-up of the lamps, because it looks quite nice.

But there's a third option: change the visual appearance a little.
Image

Instead of instant-on, instant-off, give them a visual warm-up period. This should probably still be staggered so groups of lights have more visual distinctiveness.

With a warm-up period, it's much less obvious that the lamp isn't perfectly synchronized with it's power consumption. This allows it to be switched over to solar panel-like consumption:
Image
And done! Zero UPS-impact lamps! Safe to pave a factory with.

Re: [Optimization] Lamp performance improvement

Posted: Wed Aug 31, 2022 6:40 am
by ssilk
The problem is, that every lamp needs to be “turned on”. Because every lamp is an extra power consumer. There is no general switch for them. They have optimized that, but for 100.000 lamps, each lamp needs to be turned on/off.

But your suggestion is maybe a way to solve this problem.

Hm. Eventually you can post your map to viewtopic.php?f=5&t=17501

Re: [Optimization] Lamp performance improvement

Posted: Wed Aug 31, 2022 6:55 am
by boskid
There are no reasons to change current lamp staggering behavior in order to optimize this logic. Electric network right now has a vector that maps from a UnitNumber into a staggeringModifier of a lamp. Currently this code has a linear complexity O(N) while lamps are turning on because electric network has to scan this entire vector to count how many elements fulfill the staggering value condition. There are some possibilities to rewrite this code to have a vector of staggering modifiers in a non-descending order that would allow counting how many lamps are turned on using a binary search reducing time complexity down to O(log N). In the end this logic only needs to produce one number: how many lamps are to be reported as consuming energy in current tick (using current surface's daytime).