Skip to content

Commit d8fabf5

Browse files
fix: Replaced HashSet.UnionWith() with loop in NetworkBehaviourUpdate() to avoid heap alloc (#3568)
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 Requires up-port --------- Co-authored-by: Emma <[email protected]>
1 parent caac92d commit d8fabf5

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
@@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1414

1515
### Fixed
1616

17+
- Removed allocation to the heap in NetworkBehaviourUpdate. (#3568)
1718
- Fixed issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. (#3565)
1819

1920
### Changed

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 o in m_PendingDirtyNetworkObjects)
38+
{
39+
m_DirtyNetworkObjects.Add(o);
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)