No Laggy Bed

If you liked this item, please rate it up on Steam Workshop page.

Author: telardo

Last revision: 24 Oct, 2022 at 00:20 UTC (4)

File size: 56.32 KB

On Steam Workshop

Description:

(1.3) Fix the fps drop when you select a bed or workbench.
(1.3 Optional) Fix the fps drop when you open the Needs Tab of a pawn.
(1.4) Optimize Thoughts rendering in the Needs Tab of a pawn.

Important Notes for 1.4:

Is it still needed in 1.4? I did some tests with the performance analyzer. (Bless Dubwise.)

TL;DR: In 1.4, Devs have fixed the culpirts of laggy beds and most of the Needs Tab’s. You can get a modicum of performance gain from Needs Tab with this mod in 1.4.

Long, boring technical facts are listed as follows.
For the part of beds, Devs use cached Designators in BuildCopyCommandUtility.FindAllowedDesignator() after resolving them once. They actually should do it that way long before, but it’s a good fix.

For the part of Needs Tab, some people might have noticed, in the mod setting of this mod back in 1.3, there is a default-false option called "Optimize the Needs Tab". It’s my effort addressing unoptimized thoughts rendering in that tab. Surprisingly (Maybe), devs also tried to fix this issue in 1.4. They use a cached mood offset of groups in PawnNeedsUIUtility.GetThoughtGroupsInDisplayOrder(), which is the main culprit here. However, there is still unneccessary computations in NeedsCardUtility.DrawThoughtGroup(), which calls ThoughtHandler.GetMoodThoughts() and ThoughtHandler.MoodOffsetOfGroup(). (TBH, if I were part of the devs, I may rewrite the ThoughtHandler from ground up. It’s terrible.) That’s what this mod trying to fix in 1.4. From my tests, that rendering method can be boosted from average 1.5ms to 1ms on a test pawn. Unsurpringly, it’s not quite a visible boost compared with 1.3.

Story ends. Perhaps I should call it "No laggy Needs" in 1.4, LOL. It’s a mixed feeling where sometimes you feel your effort is in vain, but at some moments, you feel good as if every game players becomes your subscribers. Anyway, embrace the change~ Thank you for the long journey with this mod and good luck.

Details:

Some players (usually heavy-modded) experience this fps issue in their game when selecting a bed or workbench. I wish this mod fixed it.
I also add an experimental fix for fps drop when opening the Needs Tab. You can activate it in mod setting page.

FAQ:
  1. Can be safely added to or removed from your current save.
  2. I suppose there are no compatibility issues. Contact me if you find one.

As usual, I don’t need donations. You can rate my mods to support me~

Technical Details:

If you’re not curious about where it comes from, stop here.
Long story short: this is a vanilla problem; more mods exacerbate it.

When you select a bed or a workbench, the game will try to find available linkable facilities like dressers and show them. BuildCopyCommandUtility.FindAllowedDesignator() scans all the designators in the database every frame to find a single build command. Typically, a game with a medium-size mod list contains thousands of designators. Hence, the game needs to validate millions of designators in 60 frames for a bed with 10ish linkables. The same case applies to workbenches. That’s the main reason why selecting them slows down your game drastically. The situation worsens with more modded buildable things. For example, VE furniture series add tons of buildable things in the game. In this mod, I build copies for needed designators and cache them to avoid scanning.

Some people claim the mod SRTS Expanded is also the culprit. To some extent, they’re right. SRTS has a harmony patch for research projects, which costs 0.005ms per call. It’s not bad itself but calling it 10k times per frame is. To avoid this, I also add caching for Designator_Build.Visible. It eliminates calling that method as much as possible, and it’s not a problem now. This caching should also speed up general gizmo drawing.

At last, I also replace GetRoom() in Building_Bed.DrawExtraSelectionOverlays() with a cached version. It’s a small lift without getting them every frame.

No free lunch! So what’s the price? Like other performance optimizers, it needs a little more memory to store the cache. It’s not a big deal from my testing. Of course, there might be other impacts I didn’t notice; if you find something, feel free to let me know.

Above is all my understandings of this problem. Please don’t quote me on that~

Download
Revisions:

Old revisions of this mod are available below. Click the link to download.