Skip to content

Reduce lag spikes from SquadManagerBotModule.#21473

Merged
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:ai-squad-perf
Jul 8, 2024
Merged

Reduce lag spikes from SquadManagerBotModule.#21473
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:ai-squad-perf

Conversation

@RoosterDragon

Copy link
Copy Markdown
Member

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

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.
@anvilvapre

Copy link
Copy Markdown
Contributor

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.

@RoosterDragon

Copy link
Copy Markdown
Member Author

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.

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PunkPun PunkPun merged commit 0d84804 into OpenRA:bleed Jul 8, 2024
@PunkPun

PunkPun commented Jul 8, 2024

Copy link
Copy Markdown
Member

changelog

@RoosterDragon RoosterDragon deleted the ai-squad-perf branch July 8, 2024 15:27
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.

Make 'squadmanager' does not tick squads all in one tick

3 participants