perf: significant performance optimizations on ordered behaviour collectors by using a sorted dictionary

This commit is contained in:
2025-10-13 09:58:58 +03:00
parent 9ccf7b754d
commit c7d170fad9
9 changed files with 152 additions and 141 deletions

View File

@@ -5,10 +5,11 @@ namespace Engine.Core;
public class UniverseEntranceManager : Behaviour
{
// We use Ascending order because we are using reverse for loop to call them
private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
private readonly ActiveBehaviourCollectorOrdered<IEnterUniverse> enterUniverses = new() { SortBy = SortByAscendingPriority() };
private readonly ActiveBehaviourCollectorOrdered<IExitUniverse> exitUniverses = new() { SortBy = SortByAscendingPriority() };
private readonly ActiveBehaviourCollectorOrdered<int, IEnterUniverse> enterUniverses = new(GetPriority(), SortByAscendingPriority());
private readonly ActiveBehaviourCollectorOrdered<int, IExitUniverse> exitUniverses = new(GetPriority(), SortByAscendingPriority());
private readonly List<IEnterUniverse> toCallEnterUniverses = new(32);
private readonly List<IExitUniverse> toCallExitUniverses = new(32);