From 4dd29f03a97afbaf916bc1ad66762c18a9945de4 Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 4 Aug 2023 12:41:41 +0800 Subject: [PATCH] STOPWATCH --- Assets/Mirror/Core/NetworkServer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index 800739934..ff435d79a 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 { @@ -1711,6 +1713,8 @@ static bool DisconnectIfInactive(NetworkConnectionToClient connection) internal static readonly List connectionsCopy = new List(); + static Stopwatch watch = new Stopwatch(); + static void Broadcast() { // copy all connections into a helper collection so that @@ -1724,6 +1728,8 @@ static void Broadcast() connectionsCopy.Clear(); connections.Values.CopyTo(connectionsCopy); + watch.Restart(); + // go through all connections foreach (NetworkConnectionToClient connection in connectionsCopy) { @@ -1755,6 +1761,8 @@ static void Broadcast() connection.Update(); } + 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: