@@ -1187,9 +1187,10 @@ private void SpawnNetworkObjectLocallyCommon(NetworkObject networkObject, ulong
11871187 }
11881188 }
11891189
1190-
11911190 internal Dictionary < ulong , NetworkObject > NetworkObjectsToSynchronizeSceneChanges = new Dictionary < ulong , NetworkObject > ( ) ;
1192- internal List < ulong > CleanUpDisposedObjects = new List < ulong > ( ) ;
1191+
1192+ // Pre-allocating to avoid the initial constructor hit
1193+ internal Stack < ulong > CleanUpDisposedObjects = new Stack < ulong > ( ) ;
11931194
11941195 internal void AddNetworkObjectToSceneChangedUpdates ( NetworkObject networkObject )
11951196 {
@@ -1212,23 +1213,22 @@ internal void RemoveNetworkObjectFromSceneChangedUpdates(NetworkObject networkOb
12121213 }
12131214 }
12141215
1215- internal void UpdateNetworkObjectSceneChanges ( )
1216+ internal unsafe void UpdateNetworkObjectSceneChanges ( )
12161217 {
12171218 foreach ( var entry in NetworkObjectsToSynchronizeSceneChanges )
12181219 {
12191220 // If it fails the first update then don't add for updates
12201221 if ( ! entry . Value . UpdateForSceneChanges ( ) )
12211222 {
1222- CleanUpDisposedObjects . Add ( entry . Key ) ;
1223+ CleanUpDisposedObjects . Push ( entry . Key ) ;
12231224 }
12241225 }
12251226
12261227 // Clean up any NetworkObjects that no longer exist (destroyed before they should be or the like)
1227- foreach ( var networkObjectId in CleanUpDisposedObjects )
1228+ while ( CleanUpDisposedObjects . Count > 0 )
12281229 {
1229- NetworkObjectsToSynchronizeSceneChanges . Remove ( networkObjectId ) ;
1230+ NetworkObjectsToSynchronizeSceneChanges . Remove ( CleanUpDisposedObjects . Pop ( ) ) ;
12301231 }
1231- CleanUpDisposedObjects . Clear ( ) ;
12321232 }
12331233
12341234 internal void SendSpawnCallForObject ( ulong clientId , NetworkObject networkObject )
0 commit comments