mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
perf: NetworkServer.Update avoid costly NetworkIdentity null check. Catch exception and log useful warning instead. This amounted to ~5% CPU in 4k monsters test before.
This commit is contained in:
parent
31b07ae02f
commit
9bd1d92b8e
@ -514,16 +514,23 @@ public static void Update()
|
|||||||
// update all server objects
|
// update all server objects
|
||||||
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)
|
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)
|
||||||
{
|
{
|
||||||
NetworkIdentity identity = kvp.Value;
|
// try to update.
|
||||||
if (identity != null)
|
// spawned might have null entries if the user made a mistake.
|
||||||
|
//
|
||||||
|
// IMPORTANT: do not check kvp.Value != null. this is way too
|
||||||
|
// costly due to Unity's custom null check
|
||||||
|
// instead, catch the exception if it happens.
|
||||||
|
// (see 4k benchmark).
|
||||||
|
try
|
||||||
{
|
{
|
||||||
identity.ServerUpdate();
|
kvp.Value.ServerUpdate();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// spawned list should have no null entries because we
|
// spawned list should have no null entries because we
|
||||||
// always call Remove in OnObjectDestroy everywhere.
|
// always call Remove in OnObjectDestroy everywhere.
|
||||||
logger.LogWarning("Found 'null' entry in spawned list for netId=" + kvp.Key + ". Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
// but if it does, we should let the user know how it happens
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Found 'null' entry in spawned list for netId=" + kvp.Key + ". Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user