Skip to content

Commit 293c3cc

Browse files
committed
perf: Fixed CustomMessage send scaling from O(n) to O(1) for n clients
1 parent 75dce33 commit 293c3cc

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

MLAPI/Core/NetworkingManager.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,11 @@ public void SendCustomMessage(List<ulong> clientIds, BitStream stream, string ch
228228
{
229229
if (!IsServer)
230230
{
231-
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
232-
NetworkLog.LogWarning("Can not send unnamed message to multiple users as a client");
231+
if (NetworkLog.CurrentLogLevel <= LogLevel.Error) NetworkLog.LogWarning("Can not send unnamed message to multiple users as a client");
233232
return;
234233
}
235-
if (clientIds == null)
236-
{
237-
for (int i = 0; i < ConnectedClientsList.Count; i++)
238-
{
239-
InternalMessageSender.Send(ConnectedClientsList[i].ClientId, MLAPIConstants.MLAPI_UNNAMED_MESSAGE, string.IsNullOrEmpty(channel) ? "MLAPI_DEFAULT_MESSAGE" : channel, stream, security, null);
240-
}
241-
}
242-
else
243-
{
244-
for (int i = 0; i < clientIds.Count; i++)
245-
{
246-
InternalMessageSender.Send(clientIds[i], MLAPIConstants.MLAPI_UNNAMED_MESSAGE, string.IsNullOrEmpty(channel) ? "MLAPI_DEFAULT_MESSAGE" : channel, stream, security, null);
247-
}
248-
}
234+
235+
InternalMessageSender.Send(MLAPIConstants.MLAPI_UNNAMED_MESSAGE, string.IsNullOrEmpty(channel) ? "MLAPI_DEFAULT_MESSAGE" : channel, clientIds, stream, security, null);
249236
}
250237

251238
/// <summary>

0 commit comments

Comments
 (0)