Skip to content

Commit

Permalink
STOPWATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
miwarnec committed Aug 3, 2023
1 parent db8b740 commit 5b43c91
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Assets/Mirror/Core/NetworkServer.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -1811,6 +1813,7 @@ static void FlushConnections()
internal static readonly List<NetworkConnectionToClient> connectionsCopy =
new List<NetworkConnectionToClient>();

static Stopwatch watch = new Stopwatch();
static void Broadcast()
{
// copy all connections into a helper collection so that
Expand All @@ -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:
Expand Down

0 comments on commit 5b43c91

Please sign in to comment.