Skip to content

Cache statpart_nearbyfoci calculations#37

Open
mlholland wants to merge 1 commit into
Vanilla-Expanded:mainfrom
mlholland:optimization-psyfocus-per-tick-cacheing
Open

Cache statpart_nearbyfoci calculations#37
mlholland wants to merge 1 commit into
Vanilla-Expanded:mainfrom
mlholland:optimization-psyfocus-per-tick-cacheing

Conversation

@mlholland

Copy link
Copy Markdown

Adds 1-hour caching of the logic of StatPart_NearbyFoci. Smoke testing suggests that it reduces the per-tick time of pawn meditation from 0.6ms to 0.26ms on my machine, boosting ticks per frame from about 300 for 3 meditating pawns in an otherwise empty colony to 600. Further optimization is likely possible by preventing examination of multiple meditation foci every tick, but I'm not quite sure where that logic is happening, and it would likely involve some prefix patches on vanilla code.

This results in mild delays in new psyfocus values being applied. For example, if a statue is placed next to a royally meditating pawn who also has an artistic psyfocus, they won't gain the benefit of the statue to their psyfocus gain until up to an hour later. Considering how infrequently this occurs, and the fact that at most a couple percentage points of psyfocus are lost or gained, I think this is a worthy trade-off.

I originally considered caching the meditation focus strength of a pawn. That resulted in sliiightly faster TPS (mid 600s instead of low 600s). However, I opted to NOT do that since it required prefix patching a vanilla function, which is never good for mod compatability and stability. This solution keeps avoids any harmony patches and keeps the changes contained to this mod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant