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
2 days ago
1.1 - 2.0
3.34K
Power

b [Resolved] High time usage

2 years 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.

2 years 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).

2 years 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 :(

2 years ago
(updated 2 years 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).

2 years 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.

2 years 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.

2 years ago
(updated 2 years 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 :(

2 years 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?

2 years ago

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

2 years ago
(updated 2 years ago)

testing...

2 years ago

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

2 years ago
(updated 2 years ago)

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

2 years 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