Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch shroud cell changes #7723

Merged
merged 3 commits into from Mar 28, 2015

Conversation

RoosterDragon
Copy link
Member

Significantly improves the perf issue noted in #7669 when you have many moving actors causing a lot of shroud changes.

This change reduces repeated work when actor visibilities overlap and when units move. Moving individual units should be slightly less costly in terms of performance now, and moving large groups of units together should be significantly less costly.

This shouldn't affect any in-game functionality - in particular when testing you should verify the radar and the shroud/fog still act correctly.

@reaperrr
Copy link
Contributor

Travis failed, just a style error though:

OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs:L250: [SA1513] Statements or elements wrapped in curly brackets must be followed by a blank line.

@reaperrr
Copy link
Contributor

Haven't tested this thoroughly for regressions yet (though I didn't spot any in my short test), but with massive number of migs, this improves performance approximately as much as an update delay of 15-20 in #7669, without the drawbacks. So a preliminary :+0.5: for the performance improvement.

@@ -515,6 +515,9 @@ static void RenderTick()
}
}

foreach (var player in Game.worldRenderer.World.Players)
player.Shroud.ResetChangedCells();
Copy link
Member

Choose a reason for hiding this comment

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

I suspect there will be a better place to run this from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe ShroudRenderer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't do the reset until the widgets have drawn, since the radar widget also needs this list.

Unless you just mean calling this as a static method of ShroudRenderer or something?

@chrisforbes
Copy link
Member

OH YES. 👍

@RoosterDragon
Copy link
Member Author

After a bit of IRC discussion, I've reworked the caching slightly.

Instead of the shroud maintaining a copy of changed cells until the next render, the shroud renderer and radar widget now each maintain their own copy.

  • This allows a bit of future proofing if the rendering of the world and widgets is decoupled. This design should continue to "just work", whereas the old one would break.
  • The shroud doesn't have to be hackily notified that rendering is finished.

This means performance isn't quite as good as we need to maintain two sets instead of one, but it does mean a cleaner design.

@reaperrr
Copy link
Contributor

Spotted no regressions and performance is still a lot better than without this pr ( with migs worth ~200 batches, ~25ms vs. ~45ms).
👍 for ingame, but I'll leave the merge to someone who could give the code a look-over as well.

cellsAndNeighborsDirty.Add(cell + new CVec(1, 0));
cellsAndNeighborsDirty.Add(cell + new CVec(-1, 1));
cellsAndNeighborsDirty.Add(cell + new CVec(0, 1));
cellsAndNeighborsDirty.Add(cell + new CVec(1, 1));
Copy link
Member

Choose a reason for hiding this comment

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

You may be able to use CVec.Directions here to ease readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, done.

By maintaining a set of changed cells we can avoid repeating work for cells that change multiple times before being rendered. The shroud renderer and radar widget now delay their work until they must render, and thus process each changed cell only once. This avoids significant repetition that was causing major slowdown when many actors were in the world.
This reduces us to one conversion per cell rather than two or three.
@Mailaender
Copy link
Member

No regressions for playing field and radar widget visible. 👍

Mailaender added a commit that referenced this pull request Mar 28, 2015
@Mailaender Mailaender merged commit 99283da into OpenRA:bleed Mar 28, 2015
@Mailaender
Copy link
Member

Changelog

@Mailaender
Copy link
Member

Thanks!

@RoosterDragon RoosterDragon deleted the batch-shroud-cell-changes branch March 28, 2015 23:00
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.

None yet

5 participants