Disco Science


Science labs light up with the colours of the science packs they are consuming, instead of just blue.

Tweaks
5 months ago
0.17 - 2.0
246K

i Performance

5 years ago

Performance seems to drop dramatically of you go bananas with the amount of labs on a map (active or not). Is this known? Anything that can be done about it? Maybe a simpler disco pattern? I wouldn't mind one where there is no pattern change at all, just a glow depeding on what science packs are currently being used.

5 years ago

I've put a fair bit of effort into performance, and my experience was that calculating the colours for each lab is relatively insignificant compared to just iterating through all of them. The updates are strided, meaning not every lab is updated every frame, and I've played around with the iteration approach to get it as fast as possible. I'd like to be able to only update labs when they're on screen, but unfortunately Factorio's synchronisation rules mean that everything needs to be kept in sync for all players.

Still, I'm open to any improvements if you're able to find optimisations that I missed!

5 years ago

You clearly looked into this with more knowledge than i could ever provide, but i wonder if at least when they aren't running, do they still eat up more resources?

5 years ago

Unfortunately they do still eat up resources when not running. ☹️

I could possibly prevent this, but I feel like it's not really worth the effort when the worst case (labs running) is still a really common one. I think if you're at the point where the mod is slowing down your game, you are better off disabling it. Otherwise you'll just curse my mod whenever your labs are running. 😃

5 years ago

If it CAN be done, adding it would be nice :D Also is there nothing in regards to the actual way it iterates through labs that can help performance on bigger lab setups? I'm curious, what is the exact process you made to iterate through labs to get them to behave this way?

5 years ago

Here's the loop: https://github.com/danielbrauer/DiscoScience/blob/550f39fcaa861335936ecec89c48f176ae2e1f16/src/core/labColoring.lua#L97

If you want, you could try changing the "stride" value in the file to something higher. Right now it's at 6, which means every lab gets updated every six frames. Higher numbers mean fewer labs are updated per frame, but it means animation will lag a bit.

(If you're not familiar with editing mods, you can just unzip the mod in Factorio's mods folder and it will prefer the unzipped version)

3 months ago

1500 labs ended up using about 4ms to process, 2ms for the mod and 2ms in script update which went away after i removed the mod
this feels like it should be possible to completely multithread, maybe even run on the GPU - is that even possible for a mod to do?

3 months ago
(updated 3 months ago)

I appreciate the test and timings!

First: did you know there is a high quality option which you can turn off? I’ve run tests with tens of thousands of labs and still come in under 16ms per game update (with high quality disabled).

Regarding further optimization: mods are limited to single-threaded execution on the CPU, and it’s all in Lua which is interpreted. As far as I know, I’ve addressed the low-hanging fruit: reducing work done per frame, distributing work across frames, and the big one: minimizing per-frame memory allocation. You are more than welcome to play around with the code and see if you can find more!

3 months ago
(updated 3 months ago)

I got notified of the activity here after so long and re-reading it made me curious: you never answered why exactly do the labs take up performance even when not running?

Optimizing this aspect, at least in my case, would be a noticeable improvement, as i often tend to not set up proper (read: equal) amounts of science packs and as a result the labs do not run all the time.

Now with space age and having to bring over shipments of the stuff over to nauvis only made this more pronounced.

3 months ago

Labs should take up a lot less time when they’re not running, but the restrictions of the modding API mean that the mod has to check regularly whether each lab is running or not.

3 months ago

FWIW though Vladster, I basically implemented the suggestion from your initial post: just turn off “high quality”.

New response