Major TPS impact suspected from LINQ usage in FoodFallPerTickAssumingCategory Postfix
Hi, thanks for the mod!
While playing, I noticed a consistent TPS drop when this mod is enabled.
Through profiling, the biggest hotspot appears to be inside the following patch:
HumanCattle.Need_Food_FoodFallPerTickAssumingCategory_Patch.FoodFallPerTickAssumingCategory:Postfix
After reviewing the current source code on the master branch, I suspect the performance issue may be related to the LINQ expression inside the postfix running every tick for every pawn:
RoleEffect_CattleHungerRateFactor roleEffect = (role.def.roleEffects? .Where(re => re is RoleEffect_CattleHungerRateFactor) .First()) as RoleEffect_CattleHungerRateFactor;
Since FoodFallPerTickAssumingCategory is tick-hot and called very frequently, this allocation + iteration might be causing a large amount of overhead even with small colonies.
Observations
- With this mod enabled, TPS dropped from ~300 to ~200 during normal gameplay
- Disabling the mod removed the TPS drop immediately
- Effect noticeable even with ~5 pawns
(These numbers are approximate based on observed gameplay, not formal benchmark.)
Possible fix ideas
- Cache the roleEffect per pawn
- Avoid per-tick LINQ (especially
.Where().First()) - Reuse static buffer or manual loop
Thanks!