diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index f1693a41dfe..e2b4240f8dd 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Mirror.RemoteCalls; using UnityEngine; +using Debug = UnityEngine.Debug; namespace Mirror { @@ -1811,6 +1813,7 @@ static void FlushConnections() internal static readonly List connectionsCopy = new List(); + static Stopwatch watch = new Stopwatch(); static void Broadcast() { // copy all connections into a helper collection so that @@ -1824,12 +1827,16 @@ static void Broadcast() connectionsCopy.Clear(); connections.Values.CopyTo(connectionsCopy); + watch.Restart(); + // broadcast spawned entities BroadcastDirtySpawned(); // flush all connection's batched messages FlushConnections(); + Debug.Log($"Broadcast took {watch.Elapsed.TotalMilliseconds:F1} ms"); + // TODO this is way too slow because we iterate ALL spawned :/ // TODO this is way too complicated :/ // to understand what this tries to prevent, consider this example: