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

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Engine.Core;
namespace Engine.Integration.MonoGame;
@@ -6,9 +7,10 @@ namespace Engine.Integration.MonoGame;
public class LoadContentManager : Behaviour, IFirstFrameUpdate
{
// 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<ILoadContent> loadContents = new() { SortBy = SortByAscendingPriority() };
private readonly ActiveBehaviourCollectorOrdered<int, ILoadContent> loadContents = new(GetPriority(), SortByAscendingPriority());
private readonly List<ILoadContent> toCallLoadContents = new(32);
private MonoGameWindowContainer monoGameWindowContainer = null!;