UnitAI Gathering optimisations
|Reported by:||wraitii||Owned by:|
|Priority:||Should Have||Milestone:||Alpha 26|
UnitAI's "GATHER.GATHERING" is called often (1/rate, which is around once per second) for each gathering entity. Because it does a fair few computations in its Timer Handler (checking if we still can gather, checking the range, gathering, possibly doing some dropsite related checks), it ends up being a large part of the sim Update in the late game (easily taking upwards of 10ms/frame).
There are two main things we could do:
- Avoid sending 2 messages in Perform Gather (resource Carrying & resource Supply changes). Only AIProxy subscribes, and the messages are usually redundant because multiple entities generally gather from one Supply. From profiling I'd guess this cuts time by ~10-20%.
- Here the solution would be to dynamically subscribe resourceSupply/Gatherer AIProxy (_maybe_ just supply) so that on turn's end, it queries its state and sends it to the AI. Avoids redundant work. When playing with no AI, could be de-activated entirely.
- Increase the timer interval. We currently collect one resource each "timer", but we could run the timer 2x less often and just collect 2 resources. I think given the capacities our entities have, this would be a good optimisation, effectively reducing work by 2x, and thus possibly saving up to 50% computation time.