Cache statpart_nearbyfoci calculations#37
Open
mlholland wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.