DeepFreeze Continued...

DeepFreeze Continued...

38.2k Downloads

Generation of 327kb of garbage every frame

KellanHiggins opened this issue ยท 7 comments

commented

I managed to profile KSP to figure out what was cause my game to pause every couple of seconds and it looks like Deep freeze is the culprit.

profiler

Have you run into this issue? I have tried to set up a development studio so I can track down the garbage generation (I am great at garbage tracking down) but I then ran out of patience to actually set it up. Any resources where it clearly shows how to install from start to finish a mod and I will fix this bug.

commented

Already cut down the garbage to about 20kbs per frame :). I am going to look at the garbage generated in Amp Year (about 20kb per fixed update) and see if I can get that down to under five and then throw a pull request your way.

Sorry if I came off as a jerk. I am just a garbage collection nazi :P.

commented

I know my mods generate a lot of garbage.
You only had to ask.
Unfortunately the law of economics applies.
a) My mods do not generate me income.
b) My mods I created to enjoy myself when playing KSP.
c) My mods don't cause my KSP to stutter.
d) I am grateful for anyone who has free time willing to invest that free time in my mods. Pull Requests gratefully accepted.

commented

Heyo,

Can you explain to me some of your methods?

setCryopodWindowSpecular

This seems to be set every frame, will the game set it back if it isn't set? Could we cache this somewhere and check it less or something?

commented

If your crusade is about garbage. Then how often it runs isn't the issue. Rather boxing in the strings and the FindModelComponent calls that would be causing the issue.

All the calls are from the PartModule instance. So what I would do if I had the time is cache the string names on start and find the renderers, animations, etc for each cryopod and cache them all in a nice little struct in the PartModule to store them in a list and pass that to setCrypodWindowSpecular. Same could be done for setCryopodWindowOpaque, startStripLightFlash, openCryopod, thawCryopodWindow, closeCryopod, freezeCryopodWindow, setCryopodWindowTransparent, stopStripLightFlash and so on.

It's the immutable strings that would cause the most garbage.

commented

Well I am wondering if setCryopodWindowSpecular needs to be run every frame? What does the method do in the game?

commented

As it's name suggests. It sets a Cryopod window's material shader to specular.
Does it need to run every frame? probably not. But it would need to detect when to do so... which is complicated by the fact that it is based on Camera range from the part and a few other factors. Same goes for the other methods linked in there with regards to transparent pods mod/functionality for a start.

commented

Finally got it installed and able to profile it.

The static function RSTUtilities.Transform FindInChildren(Transform transform, string name) recursive create an high amount garbage because it is using lists / lamba expressions. This generates thousands of new objects that fill up your memory and have to be garbage collected. I disable this and saved 100kbs per frame. Although the overlay no longer works which makes the game look less cooler.

As well, IsModInstalled(string assemblyName) uses Linq. This is called every frame (instead of being cached which it can be) and then generates 35kbs cause it is slipping up every mod into a huge string and then checking everything. I've disabled this as well and it removed this garbage collection problem.

TL;DR The main garbage generation is in looking for mods (whether they are installed or not) and recursively finding certain meshes through reflection. I disabled (or cached both of these) and took the garbage generation down to zero. Although your Amp Year controller is generating 20Kbs of garbage, so I may track that down. 12 Kbs for the fixed update when a kerbal is frozen too.

Interested in seeing what I did?