Power Overload


Performant, semi-realistic power distribution overhaul. Power poles can explode if the total electrical consumption on the network is too high. Use transformers to separate networks so that subnetworks do not take more power than they can handle.

Content
1 year, 2 months ago
1.1
3.07K
Power

b [Resolved] High time usage

1 year, 8 months ago

https://ibb.co/tJq2QRg
Can't build large base - lags and desync on weak CPU.
Code should be rework. I've tried but failed.

1 year, 8 months ago

Hello, I'm sorry to hear that!
Those numbers are high, but not completely unexpected, if it is a very large base. Sadly the code will never be performant enough to work with mega-bases.

Would you sending me a copy of your save please? I don't currently have any large bases using Power Overload - if you send me yours I can take a look and try and optimise the code further. You can upload it to some file-sharing site (google drive/dropbox/mega/etc).

1 year, 8 months ago

As i see, the code that checking poles is executing every tick. So it is make huge load. I've try to make is execute every second... But i can't figure what is going there. Tried to rework, but my version was more buggy :(

1 year, 8 months ago
(updated 1 year, 8 months ago)

Thanks for the save.
A large part of the problem (half, or more, of the performance impact) is the "Electric network" update time, which is caused by having so many unconnected networks. This is impossible to do anything about, since it is a fundamental part of the mod. I'll have a look at the script update performance to see if anything can be improved there (such as less checks per tick).

1 year, 8 months ago

Ok, I had a look at the profiler on your save. 5/6 of Power Overload's script time is spent on transformer processing, and only 1/6 on pole processing, so it's the transformer update code that is slow. Over half of the transformer updated code time is spent in create_update_transformer().

This is because each pole is only checked/updated every 300 ticks, whereas each transformer is updated every tick. I can't find much to optimise in the transformer code (except for game.get_surface and script.register_on_entity_destroyed), so my only idea is to not update each transformer every tick. That will be quite complex though, and unfortunately I don't have time to change that at the moment. Even if it still works perfectly, I'll only be saving 2 or 3ms on your total update time, which may not be enough to prevent it dropping below 60UPS.

1 year, 8 months ago

Also you've got Inserter Fuel Leech using a significant amount of time, which is typically not a useful mod to have lategame so I'd recommend disabling it.

1 year, 8 months ago
(updated 1 year, 8 months ago)

Ok, I made some optimisations to the transformer update code so now it only takes 3 times as long each tick as pole update, instead of 5 times as long. They still all update every tick, it will require lots more work to avoid this, which I can't do right now.

I did this by splitting create_update_transformer() into create_transformer() which does everything required to create a transformer, and check_transformer() which only does the bare minimum required each tick. And things like surface and force are stored in global instead of re-requested each tick.

That's all I'll be able to do for the foreseeable future, sorry. You've probably just reached the limit of what is possible with a mod like this :(

1 year, 8 months ago

each tick called "update_transformers()" which call "create_update_transformer(transformer_entity)" for each active transformer
And each time it re-register transforemer:
global.transformers[transformer.unit_number] = transformer_parts
And each time it registers on event:
script.register_on_entity_destroyed(transformer)

Does it really need?

1 year, 8 months ago

No, all of that was moved to only happen on creation in the latest update :)

1 year, 8 months ago
(updated 1 year, 8 months ago)

testing...

1 year, 8 months ago

https://pastebin.com/wNwqvTMY
https://ibb.co/87Gc397
A little bit better And seems to be works...

1 year, 8 months ago
(updated 1 year, 8 months ago)

So... With 1.2.6 and my patch now is playable. Thanks!

1 year, 8 months ago

1.3.1 includes further transformer optimisations: I realised that lots of the contents of check_transformer didn't need to be ran every tick and instead I can get away with only calling it every 10 seconds. So on your save that takes the Power Overload script time from ~1.2 to ~1.0 :)
https://github.com/tburrows13/PowerOverload/commit/c2e65432c736c500b9aa826c66eedce1d1743e9d

New response