Skip to content

Commit 1bcb377

Browse files
EmandMlouismclaughlinNoelStephensUnity
authored
fix: [UpPort] Replaced HashSet.UnionWith() with loop to avoid heap alloc (#3573)
Discovered while profiling a server that had frequent pending dirty network objects to process ## Changelog Fixed: Removed heap alloc in NetworkBehaviourUpdate ## Testing and Documentation - No tests have been added. - No documentation changes or additions were necessary. ## Backport This is an up-port of #3568 --------- Co-authored-by: Louis McLaughlin <[email protected]> Co-authored-by: Noel Stephens <[email protected]>
1 parent e7b14c2 commit 1bcb377

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
3030

3131
### Fixed
3232

33+
- Removed allocation to the heap in NetworkBehaviourUpdate. (#3573)
3334
- Fixed issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. (#3564)
3435
- Fixed regression issue in v2.x where `NetworkObject.GetNetworkBehaviourAtOrderIndex` was converted from public to internal. (#3541)
3536
- Fixed ensuring OnValueChanged callback is still triggered on the authority when a collection changes and then reverts to the previous value in the same frame. (#3539)

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ internal void NetworkBehaviourUpdate(bool forceSend = false)
3434
#endif
3535
try
3636
{
37-
m_DirtyNetworkObjects.UnionWith(m_PendingDirtyNetworkObjects);
37+
foreach (var dirtyNetworkObject in m_PendingDirtyNetworkObjects)
38+
{
39+
m_DirtyNetworkObjects.Add(dirtyNetworkObject);
40+
}
3841
m_PendingDirtyNetworkObjects.Clear();
3942

4043
// NetworkObject references can become null, when hidden or despawned. Once NUll, there is no point

0 commit comments

Comments
 (0)