Reduce lag spikes from SquadManagerBotModule.#21473
Conversation
Updating squads is the most expensive part of SquadManagerBotModule. It involves ticking the current squad state. This usually involves finding nearby enemies and evaluating the fuzzy state machine to decide whether to interact with those enemies. Since all the AI squads for a player get ordered on the same tick, this can result in a lag spike. To reduce the impact, we'll spread out the updates over multiple ticks. This means overall all the AI squads will still be refreshed every interval, but it'll be a rolling update rather than all at once. By spreading out the updates we avoid a lag spike from the cumulative updates of all the squads. Now the lag spike is reduced to the worst any single squad update can incur.
bfaace4 to
1623557
Compare
|
It can do not harm if at the next tick the AI comes up with either the same or different orders? Causing some sort of effect that orders are executed multiple times possibly with strange side effects. |
|
The goal of the squad update is to assess the situation and issue orders. Those orders will change over time, but that's what we want it to do. For example, maybe an AI squad decides to attack some nearby enemies. Then at the next update interval it will check again whether it wants to attack the nearby enemies. If the situation is still the same, then it will choose to attack as it did before. But if the situation has changed, it might decide on something else. e.g. if more enemies have turned up nearby, it might decide to flee instead because of the greater enemy numbers. None of this logic is affected by this PR as such, this is just what the SquadManagerBotModule is designed to do. |
Updating squads is the most expensive part of SquadManagerBotModule. It involves ticking the current squad state. This usually involves finding nearby enemies and evaluating the fuzzy state machine to decide whether to interact with those enemies. Since all the AI squads for a player get ordered on the same tick, this can result in a lag spike.
To reduce the impact, we'll spread out the updates over multiple ticks. This means overall all the AI squads will still be refreshed every interval, but it'll be a rolling update rather than all at once. By spreading out the updates we avoid a lag spike from the cumulative updates of all the squads. Now the lag spike is reduced to the worst any single squad update can incur.
Fixes #18825