From 4bf614c5cdd144f059260881da5dfa2ce884d494 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 29 May 2020 14:19:37 +0200 Subject: [PATCH] Use OccupiesSpace to avoid Mobile look-up in Move While individual trait look-ups may be cheap, if a large army that is currently standing still gets its first move-including order, the look-ups of dozens or even hundreds of actors may happen on the same tick. Therefore this may help reducing that first-order lag spike, at least a little bit. --- OpenRA.Mods.Common/Activities/Move/Move.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 00757f93cc..a82e90bdeb 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -52,7 +52,8 @@ namespace OpenRA.Mods.Common.Activities // Ignores lane bias and nearby units public Move(Actor self, CPos destination, Color? targetLineColor = null) { - mobile = self.Trait(); + // PERF: Because we can be sure that OccupiesSpace is Mobile here, we can save some performance by avoiding querying for the trait. + mobile = (Mobile)self.OccupiesSpace; getPath = check => { @@ -72,7 +73,8 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null, bool evaluateNearestMovableCell = false, Color? targetLineColor = null) { - mobile = self.Trait(); + // PERF: Because we can be sure that OccupiesSpace is Mobile here, we can save some performance by avoiding querying for the trait. + mobile = (Mobile)self.OccupiesSpace; getPath = check => { @@ -93,7 +95,8 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough, Color? targetLineColor = null) { - mobile = self.Trait(); + // PERF: Because we can be sure that OccupiesSpace is Mobile here, we can save some performance by avoiding querying for the trait. + mobile = (Mobile)self.OccupiesSpace; getPath = check => mobile.Pathfinder.FindUnitPathToRange( mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self, check); @@ -105,7 +108,8 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, Target target, WDist range, Color? targetLineColor = null) { - mobile = self.Trait(); + // PERF: Because we can be sure that OccupiesSpace is Mobile here, we can save some performance by avoiding querying for the trait. + mobile = (Mobile)self.OccupiesSpace; getPath = check => { @@ -123,7 +127,8 @@ namespace OpenRA.Mods.Common.Activities public Move(Actor self, Func> getPath, Color? targetLineColor = null) { - mobile = self.Trait(); + // PERF: Because we can be sure that OccupiesSpace is Mobile here, we can save some performance by avoiding querying for the trait. + mobile = (Mobile)self.OccupiesSpace; this.getPath = getPath;