Skip to content

Commit

Permalink
perf: stopping allocations from log in MessageHandler when not enabled
Browse files Browse the repository at this point in the history
Only create string if log is enabled.
Also adding todo about increasing level to warning
  • Loading branch information
James-Frowen committed Apr 13, 2022
1 parent 1339c79 commit d5b3292
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Assets/Mirage/Runtime/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ internal void InvokeHandler(INetworkPlayer player, int msgType, NetworkReader re
{
msgDelegate.Invoke(player, reader);
}
else
// check LogEnabled to stop allocations if not enabled
else if (logger.LogEnabled())
{
if (MessagePacker.MessageTypes.TryGetValue(msgType, out Type type))
{
// todo use warning here instead of log, it seems important to know a known type has no handler
// probably fine to leave unexpected message as log, but maybe we should handle it differently? we dont want someone spaming ids to find a handler they can do stuff with...
logger.Log($"Unexpected message {type} received from {player}. Did you register a handler for it?");
}
else
Expand Down

0 comments on commit d5b3292

Please sign in to comment.