Rework PriorityQueue for performance.
- Providing the comparer as a type argument that is a struct allows the calls to be devirtualised, leading to approx a 3x performance improvement. - Use a single backing array, rather than a list of arrays.
This commit is contained in:
@@ -77,12 +77,8 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
/// </summary>
|
||||
public readonly struct GraphConnection
|
||||
{
|
||||
public static readonly CostComparer ConnectionCostComparer = CostComparer.Instance;
|
||||
|
||||
public sealed class CostComparer : IComparer<GraphConnection>
|
||||
public readonly struct CostComparer : IComparer<GraphConnection>
|
||||
{
|
||||
public static readonly CostComparer Instance = new CostComparer();
|
||||
CostComparer() { }
|
||||
public int Compare(GraphConnection x, GraphConnection y)
|
||||
{
|
||||
return x.Cost.CompareTo(y.Cost);
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
this.heuristicWeightPercentage = heuristicWeightPercentage;
|
||||
TargetPredicate = targetPredicate;
|
||||
this.recorder = recorder;
|
||||
openQueue = new PriorityQueue<GraphConnection>(GraphConnection.ConnectionCostComparer);
|
||||
openQueue = new Primitives.PriorityQueue<GraphConnection, GraphConnection.CostComparer>(default);
|
||||
}
|
||||
|
||||
void AddInitialCell(CPos location, Func<CPos, int> customCost)
|
||||
|
||||
Reference in New Issue
Block a user