fluffy-mods / ColonyManager

Colony manager for RimWorld
Other
72 stars 38 forks source link

Dubs Resource Monitor shows that Colony Manager takes high perfomance consumption with 200+ mods #153

Open Taranchuk opened 4 years ago

Taranchuk commented 4 years ago

Describe the bug Dubs has released a new mod Resource Monitor https://github.com/Dubwise56/ResourceMonitor, which shows the resource consumption by mods. After installing that mod, I found that Colony Manager ranks first in terms of resource consumption, above Core. screenshot1 I tried to test with just Core, Hugslib and Colony Manager and this time performance consumption was much lower. screenshot2 Since the matter is in other mods, I began to throw out mods and measure stats and could not find a specific culprit, it seems that every mod that adds things adds to the performance consumption of Colony Manager. In the end, I managed to reduce the consumption of the Colony Manager by simply putting the condition if (Find.TickManager.TicksGame% 60 == 0) in the function public override void MapComponentTick() below the line base.MapComponentTick(); enclosing the rest of the code below in a block. Final screenshot after modification: screenshot3 Expected behavior
Less performance consumption with 200+ mods Steps to reproduce

  1. Install the mod Resource Monitor
  2. Install other 200+ mods
  3. Watch the tab "Mods"

Other mods
ModsConfig.zip

Output log
https://gist.github.com/HugsLibRecordKeeper/29637aa1ecdaeb3cbf0c922c3331214f Save game
test.zip

Screenshots
screenshot1 screenshot2 screenshot3

Environment
Windows 10 64 bits

Game 64 bits Steam 1.0

Noroji commented 4 years ago

Adding some GIFs about how often the GC runs and how much memory it takes on my machine, as talked about with Fluffy on Steam. Both are on 4X speed on a low-end machine.

GC Cleans No Manager GC Cleans With Manager

FluffierThanThou commented 4 years ago

I've just pushed a few changes which should at least resolve some of the issues with high CPU usage on an empty colony.

Please let me know what it plays like, and in particular if you found any problems with specific tabs or types of jobs.

Noroji commented 4 years ago

Massive improvement as long as no jobs are managed at all. Also, it seems for a small Colony, jobs that manage your animals seem to create low CPU usage and the GC doesn't run as often. Cannot play with more than 3 Pawns/10 Animal Colonies due to bad PC.

But: It still uses quite a bit of CPU time/creates garbage as soon as you activate a job. As before, no pawn currently working at the Manager Desk, just having the job activated makes the GC run more often (though it sure is better then before).

E.G.: If I activate a job to hunt all Predators (currently two on the Map) on a small Map, the GC starts running a bit more often (In my tests with hunting job paused I had about 30 seconds before the next GC clean started, with hunting active it was at 20 seconds).

It still is a massive improvement over what happened before, so thanks for the quick check on it!

Also I have, so far, not seen any problems with the jobs in themselves, seem to work fine for me.

Quick question, if you don't mind: Why is it necessary to check the Map all the time as soon as a job is active and not do it only when a pawn is managing it at the desk? Haven't had too much to do with Rimworld/Harmony so probably just a bad idea from me, as it sounds way too simple.

FluffierThanThou commented 4 years ago

Glad to hear this at least partially resolved the problem.

Jobs are always going to incur a certain amount of overhead. In part that is because I need to check if the job needs to be refreshed - e.g. what amount of meat is in your stockpiles and current designations for a hunting job. The idea is that this check is going to be as quick as possible (which is why 'count all on map' is disabled by default), but I may have taken unfortunate shortcuts at some point(s), which is why this kind of feedback is so valuable to me.

The second part of the overhead is when a job is actually run. This is pretty much insurmountable, .as it's just integral to the process. Still, I'm sure further improvements could be made there.

If you can find any specific cases where something is taking much longer than you'd expect, I'd love it if you could share a save game with instructions to replicate, so I can have a direct look at the proplem.

Noroji commented 4 years ago

It not only partially resolved the problem, it made it much much better, atleast for me. You have already more than doubled the amount I can play instead of looking at a frozen screen. ;-) Thanks for the quick work!

So basically you have to check every X Ticks if one of the Jobs needs to run the next time a Pawn goes to the Manager Desk and designates all targets - correct? I guess theres no easy way around like only checking it depending on the settings on how often you like to do the "Managing" Job. Or if they're would be a way, it would need a lot of work, atleast as far as I understand the Job System in Rimworld.

The second part is fine and the load on the system is fully understandable, but I run small maps and small colonies, so maybe someone that runs bigger colonies might give you more insight if there are more problems there.

If I find anything while playtesting I will try to send you a save, though I'm using about 100 other mods and it may be hard to recreate them. But so far it all seems good and the times are about as what I would expect for a mod that has that much stuff going on all the time.