perf: Improved performance for large number of NetworkObjects
Presently every NetworkObject is checked for each client every tick to see if it has dirty NetworkVariables that require syncing. This causes poor performance with large numbers of NetworkObjects as they all are checked multiple times per frame regardless of whether or not they have changed.
This PR changes the behaviour of NetworkVariables such that they register themselves with the NetworkManager for updating when they are marked dirty so there are no redundant checks.
In com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs there is a tiny local variable name inconsistency:
foreach (var dirtyObj in m_DirtyNetworkObjects)
vs
foreach (var sobj in m_DirtyNetworkObjects)
(old local variable name)
even though this sounds and looks like a bold change, it actually makes quite a lot of sense to me. perhaps, we might consider this as an optimization task/goal some time @Unity-Technologies/multiplayer-sdk
Nice PR! Trying to have it work with our test setup required a bit of tweaks.
I've opened: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/2116 which integrates this plus other changes so that it doesn't break our tests.
OK if I close this and we migrate the discussion over there?
Nice PR! Trying to have it work with our test setup required a bit of tweaks.
I've opened: #2116 which integrates this plus other changes so that it doesn't break our tests.
OK if I close this and we migrate the discussion over there?
Thanks Jeff! Great to see this gaining traction. Ok to close this one.