Improbable Icon

Forums

Unity-gdk component generated code produce 1.3kb garbage for each new entity schema component type

unity
unity-gdk

#1

You can check it with Unity Blank project sample.
Here is the profiler with 1 of my component is “Tree”


This happen due to Generated code use make boxing happen when create new Class Entity ArchetypeQuery everytime it is called.

I guess everyone thought this one is struct but it is not.
image

Edit: this happen every Unity Update(). So it have significant performance impact


#3

Hello VAD,

The allocation you’re seeing in the inspector is 2 parts.

  1. About 0.5KB is allocations by unity’s memory safety “sentinels” for NativeArray’s, which are created in the ExecuteReplication function of each component when we iterate over them for replicated to SpatialOS .
  2. There is a 0.8KB allocation from the SpatialOS C# SDK in every Send* function.

The first allocation is significantly reduced in 2018.3, and the second is a bug that we’ve found and should be fixing in a future patch release with the 13.6 C# SDK release.