Skip to content

Improve performance of AIUtils.FindQueues#21474

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

Improve performance of AIUtils.FindQueues#21474
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:ai-queue-perf

Conversation

@RoosterDragon

Copy link
Copy Markdown
Member

The AI would often invoke this method inside of loops, searching for a different category of queue each time. This would result in multiple searches against the trait dictionary to locate matching queues. Now we alter the method to create a lookup of all the queues keyed by category. This allows a single trait search to be performed.

UnitBuilderBotModule and BaseBuilderBotModule are updated to fetch this lookup once when required, and pass the results along to avoid calling the method more times than necessary. This improves their performance.

The AI would often invoke this method inside of loops, searching for a different category of queue each time. This would result in multiple searches against the trait dictionary to locate matching queues. Now we alter the method to create a lookup of all the queues keyed by category. This allows a single trait search to be performed.

UnitBuilderBotModule and BaseBuilderBotModule are updated to fetch this lookup once when required, and pass the results along to avoid calling the method more times than necessary. This improves their performance.

@anvilvapre anvilvapre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Untested.

@anvilvapre

anvilvapre commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

Reading this again. Having a Player.BotContext?.QueueByCategory would be overkill? Since now you may build the map for the sample player multiple time? Or are the categories too few and is it too unlikely that all three callers will be instantiated.

The same context could cache certain manager traits.

Comment thread OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs
@RoosterDragon

Copy link
Copy Markdown
Member Author

Reading this again. Having a Player.BotContext?.QueueByCategory would be overkill? Since now you may build the map for the sample player multiple time? Or are the categories too few and is it too unlikely that all three callers will be instantiated.

Likely more complexity than it's worth - it'd need to be refreshed every time queues were built, changed owners, toggled between enabled and disabled, etc.

@PunkPun
PunkPun merged commit c45e78c into OpenRA:bleed Jul 26, 2024
@RoosterDragon
RoosterDragon deleted the ai-queue-perf branch July 26, 2024 20:05
@PunkPun

PunkPun commented Jul 26, 2024

Copy link
Copy Markdown
Member

changelog

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.

3 participants