Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lag in Caravan Screen #32

Closed
Vectorial1024 opened this issue Jul 10, 2022 · 12 comments
Closed

Lag in Caravan Screen #32

Vectorial1024 opened this issue Jul 10, 2022 · 12 comments
Labels
bug Something isn't working question Further information is requested

Comments

@Vectorial1024
Copy link
Owner

Multiple Steam users report extreme lag with the Caravan UI. It would seem to originate from the People and Animals tab in some of the caravan GUIs.

Not sure what is going on for the moment, but perhaps there are some unexpected side effect that I did not notice, or there are some hidden assumptions that I used + does not hold in the relevant GUI screens.

Or, maybe there are some hidden optimizations that can be done, just like how I previously improved the performance of Real Time Clock Plus just by discovering and using the ToStringCached function instead of the usual ToString.

What is strangest, is that there are no error logs. This rules out exception-based lag, but rather logic-based lag.

Regardless, a deeper look is needed.

@Vectorial1024 Vectorial1024 added bug Something isn't working question Further information is requested labels Jul 10, 2022
@SeppDE
Copy link

SeppDE commented Jul 10, 2022

If more informations are needed just tag me here.

@seldonPlan
Copy link

Can confirm this issue in my game. I dont see any errors logged.

Here is my hugs log: https://gist.github.com/997a7347c6600c1203fb2b26062e5879

And here is a stack trace of what i think is the offending call that is tanking performance: https://imgur.com/a/ZZR7qVf

@seldonPlan
Copy link

So, for whats it worth, i've tested my game with different versions of EBF 5.0.3, 5.0.2, 5.0.1, 5.0.0 and 4.0.9. I see the same slowdown behavior in all of the 5.0.* versions. I know that doesn't tell you much since version 5 seemed like a pretty big re-work, but the performance issue did go away when i switched to 4.0.9

i dont have any of the mods installed your unification layer seemed to be addressing, so I dont think its a conflict there.

@Vectorial1024
Copy link
Owner Author

Vectorial1024 commented Jul 12, 2022

The main deal with the v5.* family is about Community Unification, which basically means using C# reflection to execute functions that would otherwise require separate patch mods if made by the less tech-abled modders.

Because we are using reflection, the performace will be poorer than directly using machine code in the C# dlls, but I expected that "it wont be that bad"...

From the attached log it seems something is going on with AchievementsExpanded.AchievementCard ...?

I also see your tracing screenshot, but just in case, which tool were you using to get that info? I want to explore a bit on my side to see if I can get something similar, also to get familiar with using profilers etc.

Edit: to add to this, a while ago I replaced my laptop due to some other reasons, and now my current laptop is much more powerful than my previous laptop, so it is possible that "I did not see this performance problem on my side" because my laptop is simply too fast that no lag can be seen, so I am trying to get your profiler to see if the numbers are larger than usual.

@seldonPlan
Copy link

The tool is Dub's Performance Analyzer, on steam...

I use a fork of that project by user @simplyWiri of that project with some slight re-tooling of the UI, and some additional troubleshooting categories https://github.com/simplyWiri/Dubs-Performance-Analyzer

For what it's worth, there is also a pretty active performance optimization focused discord group: https://discord.com/channels/241677926855081984/660280287497814078 , i've seen the folks over there help other mod authors with stuff like this

@seldonPlan
Copy link

as for my log, there is definitely something borked with the Achievements expanded. I yanked that mod mid-way through my current play through and i am still seeing some vestigial issues that i havent been able to fix. That said, i dont think that is the particular issue here. I run quite a few other mods with minimal issues, and my machine seems to keep up fine with a TPS in high 300's at 3x speed (without EBF, that is)

@Vectorial1024
Copy link
Owner Author

For Achievements Expanded, my guess is that it injected some string value into some savedata, and those strings are actually defNames of Achievement Expanded data structures.

It keeps throwing errors because the savedata could be loaded fine (ie not corrupted) but the game could not find the defs as specified by the string.

I'll just setup the profiler first and investigate later.

@Vectorial1024
Copy link
Owner Author

Vectorial1024 commented Jul 13, 2022

I opened up the profiler, and indeed there is a great lag, and with my rather powerful laptop, it only showed up as an (personally) acceptable fps drop. It was not outright unusable so it slipped past unnoticed.

One thing to notice is that there are many many calls to GetMaxHealth , which does not seem right...? it is mainly the many calls to GetMaxHealth that is causing the lag.

Edit: one thing to point out: it just seem strange that I seemingly cannot find any profiler record of GetMaxHealth if I disable EBF... so in the strictest sense, I cannot compare the performances correctly

@Sindusk
Copy link

Sindusk commented Jul 15, 2022

I noticed it becomes outright unusable when you have a significant amount of pawns. The issue directly scales with how many pawns are displayed on the screen, and I noticed it becomes essentially unusable around 20 pawns. Not noticeable early on, but very noticeable later in the game.

@Vectorial1024
Copy link
Owner Author

Every computer system becomes unusable when there is too much going on, but becoming unusable with only 20 pawns is unacceptable.

Something is going on with the seemingly excessive amount of calls to the GetMaxHealth function.

@Vectorial1024
Copy link
Owner Author

Vectorial1024 commented Jul 16, 2022

I do not know why the function had to be called many many times, but apparently the most number of calls came from

  • HediffSet GetPartHealth
  • Pawn Capacity calculation
  • Moody UI display
  • (Edit:) Pawnmorpher GetPartMaxHealth

In fact when I think about it, when we are forming caravans the game will be paused, so eventually most of those calls are expecting the same value. Might as well cache those values for a great peerformance boost.

I will release the update later, but when testing locally with the Performance Analyser, the performance is now greatly improved, to the point where there is virtually no performance impact whatsoever:

Screenshot

I'll see if I can also deal with #33 and push them both in the same update.

Edit/update:

On my side, before the patch, if I didnt use any other mods and went to the caravan screen, I got roughly 20 fps. After I fixed that, I got 40 fps, which is OK and indicates that the game is running smoothly.

Then, I enabled Pawnmropher to test sth else, and boy, entering the caravan screen tanked the fps to ~10 fps. I fixed it again, and it returned to 40fps. I can see when you are using Pawnmorpher, the Pawnmorpher calculation + the vanilla social interaction/social fight/etc calculation can tank fps to perhaps 5 fps.

@Vectorial1024
Copy link
Owner Author

I'm closing this because v5.0.4 (released) has solved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants