RimWorld

RimWorld

YouDoYou
This topic has been locked
Riftwalker 11 Jul, 2021 @ 12:25am
Beefy Map component Tick (noticed lag)
Running into a big problem with this mod's map component tick, it's pretty big and likely would put it on the slow mods list[docs.google.com] if anyone's actually updating that thing. using dubs analyzer

it appears to update every pawns priorities every like, idk 300 or so ticks where it spikes to 54 or more ms for me with 20 colonists. the average for me with 20 seems to be 1.5ms average but mostly spikes, this is huge as most map components average less than 0.05ms

if you could make it so on each of these ticks it updates only 1 pawn and cycles through them you could get away with updating more often but overall slower per pawn for a smoother play time.

If instead it's more about the bigger updates like do pops need tending or checking supplies etc, then you could divide those checks to spread out over time instead of cycling through pawns and could even do both if they're both processing hogs.

most of the lag occurs in Rimworld.Pawn_workSettings:SetPriority(probably like 95% of it, it's hard to figure out an average when it spikes every few seconds) so this would be to refactor code if you'd like to try from that angle.

Also i noticed it does this even with all pawns asleep, you might be able to find a way of skipping updating the sleeping pawns

NOTE: I wrote all of this while investigating and found that worktab has a patch that makes the mapcomponent take about 6 times longer than without it(probably as it updates the subtasks). Removing the mod put it down to average of .22-.27 but still spikes to 35ms occasionally but usually only takes 4-5ms. this is still pretty beefy, and any reduction here will likely have a relative reduction to those using worktab, so I thought I wouldn't delete what I found so far as it could still greatly improve performance and make for a smoother experience.

I'll likely keep using worktab as this mod still has the problem that only work tab really fixed for me. having a single pawn who specifically prioritizes hauling to blueprints reduces construction times by like 7 and that's really important when recovering from assaults and the like.

Note Note, i'm going to continue testing tomorrow but I noticed that the call has 2 humps[i.imgur.com] one near the beginning and one near the end, when the super spikes happen the spike is near the end of the second hump.

Tomorrow I'll probably update how toggling free will changes things.
< >
Showing 1-8 of 8 comments
Riftwalker 11 Jul, 2021 @ 12:38am 
ok nvm, did a super quick test where I set half to have no freewill and there was about half-as long of a time it took to do it, if you update the pawns 1 at a time hopefully that would greatly increase playability,

also sorry if I come off as annoying, i know you might not really want this help or even think of it as help, but I enjoy poking into mods that are laggy and finding out why.
freemapa  [developer] 11 Jul, 2021 @ 4:28pm 
I do update the pans one at a time. But calculating some steps does take a bit of time. Planning to smooth it out more as I move towards an official release. During beta, I'm not really worrying about running a bit slow, as long as it's playable with vanilla.

But thanks for reporting all this! Super helpful!
Riftwalker 11 Jul, 2021 @ 7:27pm 
no, problem, limiting freewill makes the mod still manageable.

I find it strange you do it one at a time if free has the effect i noticed.

I mean updating the pawns priorities, like cycle through the pawns and do them 1 at a time after 30 or 60 ticks. so like 60 ticks pawn 1 checks the saved global stuff like do pawns need tending, then calculates using their personal properties, applies them, and then 60 ticks later pawn 2 does this, then every 600 ticks you update all of the global stuff or if that's too much of a spike, you calculate them 1 at a time like the pawns except it's calculate iscookingdirty, then 120 ticks isplantblighted, etc. like I said above, setting the priorities seems to have the biggest impact currently. if calculating the priorities are inside there they should be moved around. because i don't really know what the internals of rimworld look like it's hard to say but it appears the applying of priorities is what's a hog since it seems proportional to the number of job priorities and the number of pawns.

just the things that come to my mind, hope your release goes well.
freemapa  [developer] 12 Jul, 2021 @ 7:13pm 
So the way it works is that there are several prep calculations done, one on each tick. Then the pawns are processed, one on each tick. Then there is a rest period where the mod is essentially not doing anything.

I'll probably eventually move to a process where only one pawn and one work type is processed per tick. This should really smooth things out.
Riftwalker 12 Jul, 2021 @ 9:32pm 
ok, if I could ask one thing of you as a favor, can please make a way to disable the mass logging you do for things not having a custom ruleset for a worktype >.<

I know not super important but boy does it make reading logs a pain. XD

don't worry about it though if it's too much work.
freemapa  [developer] 13 Jul, 2021 @ 12:21am 
just fixed it
freemapa  [developer] 13 Jul, 2021 @ 5:23am 
I got a new build that gets the vanilla ticks down to sub ms times (even the spikes). Not going to put it on steam yet in case I broke something. But if you want to try it, you can find it in my GitHub releases: https://github.com/paul-freeman/rimworld-youdoyou/releases/tag/beta4-prerelease1
Riftwalker 13 Jul, 2021 @ 10:46am 
Nice, I found that there was also a conflict with a pawnmorpher patch and that was probably why I was getting so high spikes(they patch checking for forbidden work types) as well.

with worktab+pawnmorpher it's at .3ms average and the graph is much smoother with spikes of 8ms(very rarely goes to 50ms), feels much nicer to play with. sometimes the average stays around .25 and spikes are less frequent at night.

the spikes still seem related to worktab's patch though, very strange as they only happen like once every 2000+ ticks, so no concern for you.
< >
Showing 1-8 of 8 comments
Per page: 1530 50