Skip to content

Use Array.IndexOf to speed up Shroud.Tick.#21185

Merged
PunkPun merged 3 commits into
OpenRA:bleedfrom
RoosterDragon:shroud-perf
Nov 4, 2023
Merged

Use Array.IndexOf to speed up Shroud.Tick.#21185
PunkPun merged 3 commits into
OpenRA:bleedfrom
RoosterDragon:shroud-perf

Conversation

@RoosterDragon

Copy link
Copy Markdown
Member

As the touched cell layer uses Boolean values, Array.IndexOf is able to use a fast vectorised search. Most values in the array are false, so the search is able to significantly improve the performance of finding the next true value in the array.


Review with ignore whitespace for a cleaner diff.

Running this replay at max speed on commit 5157bc3 gives the following performance improvement. ra-2023-11-04T105726Z.zip

Before

  • Shroud.Tick 14.3%
    • OnShroudChanged 2.5%

After

  • Shroud.Tick 6.5%
    • UpdateCell 4.0%
      • OnShroudChanged 2.9%
    • IndexOf 1.8%

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

Using /all a second time now blinds you. Even when you have explored map option enabled

@RoosterDragon

RoosterDragon commented Nov 4, 2023

Copy link
Copy Markdown
Member Author

Using /all a second time now blinds you. Even when you have explored map option enabled

Looks like an existing issue on bleed, as using the /all command simulates using the "Clear Shroud" and "Reset Shroud" buttons. Have added a commit that removes those buttons from the /all command which fixes the problem.

As the `touched` cell layer uses Boolean values, Array.IndexOf is able to use a fast vectorised search. Most values in the array are false, so the search is able to significantly improve the performance of finding the next true value in the array.
Disabling the shroud is sufficient to allow seeing the map. This fixes a game with the "Explored Map" option enabled. Previously using the `/all` command twice to toggle it on and off again would also reset the shroud, causing the map to no longer be explored. Now, using it twice will cause the map to remain explored, as intended when the "Explored Map" option is enabled.
@PunkPun

PunkPun commented Nov 4, 2023

Copy link
Copy Markdown
Member

Oh hmm, it looks like this issue in in the current release as well

@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 e83e580 into OpenRA:bleed Nov 4, 2023
@RoosterDragon RoosterDragon deleted the shroud-perf branch November 4, 2023 16:46
@PunkPun

PunkPun commented Nov 4, 2023

Copy link
Copy Markdown
Member

Changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants