GhostCollectionSystem is too slow

Hi @timjohansson @CMarastoni . I notice GhostCollectionSystem takes so long time execute when spawning ghost. It’s unacceptable especially for mobile platform. At editor it’s also crazy slow. It’s even slow when in development build. I believe the main reason why it’s so slow is caused by Entities lambda expression inside the system is not burst. Is there any plan to make it burst compatible and make it even faster at both release build and development build? And also maybe change DEVELOPMENT_BUILD scripting define symbol to something like NETCODE_DEVELOPMENT_BUILD so those slow codes are stripped out at development build by default.

GhostCollectionSystem doesn’t do much when a ghost is spawned, but it does do work when a new ghost prefab is loaded.
How slow is slow and does it happen every time you spawn or just when you spawn a ghost type that has no been seen before? Do you have a profiler capture or numbers of how long it usually takes and how much it takes in the case you’re hitting?
We do not have many samples doing runtime loading of prefabs so it is not something we have seen or planned to work on at the moment, but if it is slow that sounds like something we would treat like a bug.

We have move much of the logging code to a separate define which by default is editor or development build but can be explicitly disabled or enabled to override the default behavior. Not everything is moved to that define so it might not help.
It should be very rare that you need to disable debug though, do you have a specific case where the validation is too slow so we can look at that?

Yes. It’s really slow at Android development build.

7213699--867040--1.png

Same at editor also really slow.

7213699--867043--upload_2021-6-7_15-23-0.png

For what I see in your capture, is mostly (if not all) the GC the problem. If I remember correctly we fixed some GC pressure (that may solve that issue). There are still some allocation for strings (error names) that can be definitively reduced or removed (need some further work/investigation)

From I what see the code guard with DEVELOPMENT_BUILD define still using OOP land C# data type. I think need to replace all of it to DOTS compatible data type and burst it.

Actually another bottleneck is ProcessGhostPrefab function which also spend a lot of time. I think at least make ProcessGhostPrefab function burst compatible to solve performance issue.

I investigate again and found this loading behavior also one the main reason that make GhostCollectionSystem so slow. Can u change it to only process ghost prefab that is actually spawned? Currently if I put 100 ghost prefabs into GhostCollectionAuthoringComponent and u only spawn 1 ghost from it you still pay the price for processing all the 100 ghost prefabs.

We will surely investigate that processing and trying to make it faster. But handing only the spawned ones is a little more problematic (even if it makes completely sense btw) and need some careful considerations.
Processing these prefabs is necessary for being able to detect if the client is compatible with the server is trying to connect to in the first place.
Another thing that make it tricky is that the client must process the prefab before receive the ghost data from the server, otherwise it will not be able to deserialize the ghosts. Making that initialization “lazy”, may end introducing some extra latency to spawn entities on the client (at least the first time a new ghost is spawned).

That being said, it is something we will sure consider in the analysis.

1 Like

Btw can I get unofficial fix for this huge GC spike first?

I don’t have a repro for that spike at hand so I can’t reliably test it. I have spotted some code which does a significant amount of gc allocations though. Removing them completely is a fairly large change, but I think we can reduce it significantly.
I can’t promise it will fix the issue, but if you want to help us try something out it would be great if you can move netcode to the Packages folder so you can change it, open GhostCollectionSystem.cs and change

                    var errorNames = compState.PredictionErrorNames.ToString().Split(',');
                    for (int name = 0; name < errorNames.Length; ++name)
                    {
                        if (ghostChildIndex == 0)
                            errorNames[name] = $"{ghostMeta.Name.ToString()}.{compState.ComponentType}.{errorNames[name]}";
                        else
                            errorNames[name] = $"{ghostMeta.Name.ToString()}[{ghostChildIndex}].{compState.ComponentType}.{errorNames[name]}";
                    }
                    m_PredictionErrorNames.AddRange(errorNames);

to

                    unsafe
                    {
                    int strStart = 0;
                    int strEnd = 0;
                    int strLen = compState.PredictionErrorNames.Length;
                    string ghostName = ghostMeta.Name.ToString();
                    FixedString512 errorName = default;
                    while (strStart < strLen)
                    {
                        strEnd = strStart;
                        while (strEnd < strLen && compState.PredictionErrorNames[strEnd] != ',')
                            ++strEnd;
                        errorName = ghostName;
                        if (ghostChildIndex != 0)
                        {
                            errorName.Append('[');
                            errorName.Append(ghostChildIndex);
                            errorName.Append(']');
                        }
                        errorName.Append('.');
                        errorName.Append(TypeManager.GetTypeInfo(compState.ComponentType.TypeIndex).DebugTypeName);
                        errorName.Append('.');
                        errorName.Append(compState.PredictionErrorNames.GetUnsafePtr() + strStart, strEnd-strStart);
                        m_PredictionErrorNames.Add(errorName.ToString());
                        // Skip the ,
                        strStart = strEnd + 1;
                    }
                    }

Alright. Tried just now. Still same huge GC spike.

I would like to understand how it work currently at Netcode 0.6.0-preview.7. Is that possible that I load like 8 ghost prefab entity to spawn 8 ghost entity and later load another like 10 ghost prefab entity and spawn 5 ghost entity from among that 10 ghost prefab entity?

Hi @timjohansson Have u figured out new fix for this issue?

Hi @CMarastoni Can I confirm this with u again? From my understanding, GhostCollectionSystem at both client and server will find and process ghost prefab every frame. So, as long as I make ghost prefab entity that I want to
instantiate available at both client and server first at any point of time then I can instantiate it. Even I make the ghost prefab available at late time it’s still ok right?

@CMarastoni I relook at this issue again. It’s just like what you say the slowdown mainly cause by insane GC spike that comes from all the code that guard by UNITY_EDITOR || DEVELOPMENT_BUILD define in GhostCollectionSystem.
Can you roll out unofficial fix for this issue? For now it should be fix most of the performance issue for me. At least at editor. Currently it’s stuck like over 15+ seconds when I enter play mode at editor.

So we have changes for that. Not sure if they will fix the GC spikes completely but should reduced them.
One is inside the GhostCollectionSystem, that @timjohansson already posted here and the other ones is larger and it is inside the GhostStatsCollectionSystem.cs and DebugWebSocket.cs

I will link the files here. Please try it out to see if that alleviate the problem for you. They should be completely compatible with 0.6-preview.7

7301578–884230–DebugWebSocket.cs (10.5 KB)
7301578–884233–GhostStatsCollectionSystem.cs (14.7 KB)

@CMarastoni I get NativeText could not found error.

Library\PackageCache\com.unity.netcode@34e1347be5\Runtime\Stats\GhostStatsCollectionSystem.cs(67,17): error CS0246: The type or namespace name ‘NativeText’ could not be found (are you missing a using directive or an assembly reference?)

Oh yeah, that api has changed. I think you can use the HeapString instead.

1 Like

@CMarastoni Come out another 4 errors. I think there is lot of missing code at GhostCollectionSystem. Can you send me new GhostCollectionSystem code?

Library\PackageCache\com.unity.netcode@35a52ae784\Runtime\Snapshot\GhostCollectionSystem.cs(247,89): error CS1503: Argument 1: cannot convert from ‘System.Collections.Generic.List’ to ‘Unity.Collections.NativeList<Unity.Collections.FixedString128>’

Library\PackageCache\com.unity.netcode@35a52ae784\Runtime\Snapshot\GhostCollectionSystem.cs(247,103): error CS1503: Argument 2: cannot convert from ‘System.Collections.Generic.List’ to ‘Unity.Collections.NativeList<Unity.Collections.FixedString512>’

Library\PackageCache\com.unity.netcode@35a52ae784\Runtime\Snapshot\GhostCollectionSystem.cs(357,85): error CS1503: Argument 1: cannot convert from ‘System.Collections.Generic.List’ to ‘Unity.Collections.NativeList<Unity.Collections.FixedString128>’

Library\PackageCache\com.unity.netcode@35a52ae784\Runtime\Snapshot\GhostCollectionSystem.cs(357,99): error CS1503: Argument 2: cannot convert from ‘System.Collections.Generic.List’ to ‘Unity.Collections.NativeList<Unity.Collections.FixedString512>’

You should adapt your ghost collection system a little:

OnCreate:
#if UNITY_EDITOR || DEVELOPMENT_BUILD
m_PredictionErrorNames = new NativeList(16, Allocator.Persistent);
m_GhostNames = new NativeList(16, Allocator.Persistent);
#endif

OnDestroy:
#if UNITY_EDITOR || DEVELOPMENT_BUILD
m_PredictionErrorNames.Dispose();
m_GhostNames.Dispose();
#endif

OnUpdate:
#if UNITY_EDITOR || DEVELOPMENT_BUILD
if (m_PrevPredictionErrorNamesCount < m_PredictionErrorNames.Length || m_PrevGhostNamesCount < m_GhostNames.Length)
{
World.GetExistingSystem().SetGhostNames(m_GhostNames, m_PredictionErrorNames);
m_PrevPredictionErrorNamesCount = m_PredictionErrorNames.Length;
m_PrevGhostNamesCount = m_GhostNames.Length;
}
#endif

@CMarastoni Editor just crash when I enter play mode. Are m_PredictionErrorNames and m_GhostNames not allocate large enough to use? But weird since it’s NativeList it should able to expand the size itself.

Edit: Test with very simple Netcode that has only 1 ghost also crash. There’s somewhere make it crash but I’m not sure it’s actually at where but get the editor crash log.

Stacktrace:
at <0xffffffff>
at (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.UnsafeUtility.Free (void*,Unity.Collections.Allocator) [0x00008] in <24599fe2776145d58ab771516c063d56>:0
at Unity.Collections.Memory/Unmanaged/Array.Resize (void*,long,long,Unity.Collections.Allocator,long,int) [0x0004d] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\Memory.cs:84
at Unity.Collections.Memory/Unmanaged.Free (void*,Unity.Collections.Allocator) [0x00006] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\Memory.cs:25
at Unity.Collections.AllocatorManager.TryLegacy (Unity.Collections.AllocatorManager/Block&) [0x00081] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\AllocatorManager.cs:437
at Unity.Collections.AllocatorManager.Try (Unity.Collections.AllocatorManager/Block&) [0x0001c] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\AllocatorManager.cs:456
at Unity.Collections.AllocatorManager.Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*,int,int,int) [0x0004f] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\AllocatorManager.cs:74
at Unity.Collections.AllocatorManager.Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*) [0x00000] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\AllocatorManager.cs:85
at Unity.Collections.LowLevel.Unsafe.UnsafeList.Dispose () [0x0000d] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\UnsafeList.cs:198
at Unity.Collections.LowLevel.Unsafe.UnsafeList.Destroy (Unity.Collections.LowLevel.Unsafe.UnsafeList*) [0x0000c] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\UnsafeList.cs:166
at Unity.Collections.NativeList`1.Dispose () [0x00011] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\NativeList.cs:433
at Unity.Collections.HeapString.Dispose () [0x00000] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.collections@0.15.0-preview.21\Unity.Collections\HeapString.gen.cs:211
at Unity.NetCode.GhostStatsCollectionSystem.OnDestroy () [0x00000] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.netcode@9980e7196a\Runtime\Stats\GhostStatsCollectionSystem.cs:183
at Unity.Entities.ComponentSystemBase.OnDestroy_Internal () [0x00000] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\ComponentSystemBase.cs:198
at Unity.Entities.World.DestroyAllSystemsAndLogException () [0x0004d] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\World.cs:413
at Unity.Entities.World.Dispose () [0x00031] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\World.cs:156
at Unity.Entities.World.DisposeAllWorlds () [0x00002] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\World.cs:174
at Unity.Entities.DefaultWorldInitialization.DomainUnloadOrPlayModeChangeShutdown () [0x00048] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\DefaultWorldInitialization.cs:94
at Unity.Entities.DefaultWorldInitializationProxy.OnDisable () [0x00008] in C:\UnitySample\gameplayservertest\Library\PackageCache\com.unity.entities@5e423522e5\Unity.Entities\DefaultWorldInitializationProxy.cs:29
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00020] in <695d1cc93cca45069c528c15c9fdd749>:0

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

Received signal SIGSEGV
Stack trace:
0x00007ff76e0062f9 (Unity) MemoryProfiler::UnregisterAllocation
0x00007ff76d7998eb (Unity) MemoryManager::RegisterDeallocation
0x00007ff76d795c56 (Unity) MemoryManager::smile:eallocate
0x00007ff76d7a7b8a (Unity) free_alloc_internal
0x00007ff76e9fe915 (Unity) UnsafeUtility::Free
0x00007ff76e8918e3 (Unity) UnsafeUtility_CUSTOM_Free
0x00000174fae5fbad (Mono JIT Code) (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.UnsafeUtility:Free (void*,Unity.Collections.Allocator)
0x00000174fac42cd3 (Mono JIT Code) [Memory.cs:85] Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.Allocator,long,int)
0x00000174fae5fb0b (Mono JIT Code) [Memory.cs:26] Unity.Collections.Memory/Unmanaged:Free (void*,Unity.Collections.Allocator)
0x00000174fac4545b (Mono JIT Code) [AllocatorManager.cs:438] Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&)
0x00000174fac45253 (Mono JIT Code) [AllocatorManager.cs:456] Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&)
0x00000174fac458fb (Mono JIT Code) [AllocatorManager.cs:74] Unity.Collections.AllocatorManager:Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*,int,int,int)
0x00000174fac4580b (Mono JIT Code) [AllocatorManager.cs:86] Unity.Collections.AllocatorManager:Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*)
0x00000174fe2ad8db (Mono JIT Code) [UnsafeList.cs:199] Unity.Collections.LowLevel.Unsafe.UnsafeList:smile:ispose ()
0x00000174fe2ad7eb (Mono JIT Code) [UnsafeList.cs:167] Unity.Collections.LowLevel.Unsafe.UnsafeList:smile:estroy (Unity.Collections.LowLevel.Unsafe.UnsafeList*)
0x00000175c2fa10fb (Mono JIT Code) [NativeList.cs:434] Unity.Collections.NativeList`1:smile:ispose ()
0x00000175c2fa107b (Mono JIT Code) [HeapString.gen.cs:212] Unity.Collections.HeapString:smile:ispose ()
0x00000175c2fa0e8b (Mono JIT Code) [GhostStatsCollectionSystem.cs:184] Unity.NetCode.GhostStatsCollectionSystem:OnDestroy ()
0x00000175ccdb3655 (Mono JIT Code) [ComponentSystemBase.cs:199] Unity.Entities.ComponentSystemBase:OnDestroy_Internal ()
0x00000175ccdb3243 (Mono JIT Code) [World.cs:414] Unity.Entities.World:smile:estroyAllSystemsAndLogException ()
0x00000175ccdb2a73 (Mono JIT Code) [World.cs:157] Unity.Entities.World:smile:ispose ()
0x00000175ccdb296b (Mono JIT Code) [World.cs:172] Unity.Entities.World:smile:isposeAllWorlds ()
0x00000175ccdb22fb (Mono JIT Code) [DefaultWorldInitialization.cs:96] Unity.Entities.DefaultWorldInitialization:smile:omainUnloadOrPlayModeChangeShutdown ()
0x0000017521ae522b (Mono JIT Code) [DefaultWorldInitializationProxy.cs:30] Unity.Entities.DefaultWorldInitializationProxy:OnDisable ()
0x00000175ccfa8e10 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ff92e68e630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke
0x00007ff92e612ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ff92e61bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff76e6c9464 (Unity) scripting_method_invoke
0x00007ff76e6c1db5 (Unity) ScriptingInvocation::Invoke
0x00007ff76e6c21de (Unity) ScriptingInvocation::InvokeChecked
0x00007ff76e72ed06 (Unity) SerializableManagedRef::CallMethod
0x00007ff76e67897a (Unity) MonoBehaviour::RemoveFromManager
0x00007ff76d841558 (Unity) GameObject::ActivateAwakeRecursivelyInternal
0x00007ff76d841169 (Unity) GameObject::ActivateAwakeRecursively
0x00007ff76d843d69 (Unity) GameObject::smile:eactivate
0x00007ff76df7272e (Unity) DestroyObjectHighLevel_Internal
0x00007ff76df72354 (Unity) DestroyObjectHighLevel
0x00007ff76df80a17 (Unity) DestroyWorldObjects
0x00007ff76fa1bb5b (Unity) EditorSceneManager::RestoreSceneBackups
0x00007ff76f3bf1bd (Unity) PlayerLoopController::ExitPlayMode
0x00007ff76f3d4527 (Unity) PlayerLoopController::SetIsPlaying
0x00007ff76f3d7284 (Unity) Application::TickTimer
0x00007ff76fd4ff81 (Unity) MainMessageLoop
0x00007ff76fd53fc1 (Unity) WinMain
0x00007ff771b89526 (Unity) scrt_common_main_seh
0x00007ff9ae2b7034 (KERNEL32) BaseThreadInitThunk
0x00007ff9afe62651 (ntdll) RtlUserThreadStart
ate () [0x0005f] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystem.cs:114
at Unity.Entities.ComponentSystemGroup.UpdateAllSystems () [0x000c7] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:472
at Unity.Entities.ComponentSystemGroup.OnUpdate () [0x0000e] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:417
at Unity.NetCode.ServerSimulationSystemGroup.OnUpdate () [0x000b7] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.netcode@9980e7196a\Runtime\ClientServerWorld\ServerSimulationSystemGroup.cs:75
at Unity.Entities.ComponentSystem.Update () [0x0005f] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystem.cs:114
at Unity.Entities.ComponentSystemGroup.UpdateAllSystems () [0x000c7] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:472
at Unity.Entities.ComponentSystemGroup.OnUpdate () [0x0000e] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:417
at Unity.Entities.ComponentSystem.Update () [0x0005f] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystem.cs:114
at Unity.Entities.ComponentSystemGroup.UpdateAllSystems () [0x000c7] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:472
at Unity.Entities.ComponentSystemGroup.OnUpdate () [0x0000e] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystemGroup.cs:417
at Unity.Entities.ComponentSystem.Update () [0x0005f] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ComponentSystem.cs:114
at Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper.TriggerUpdate () [0x0000f] in C:\Users\Lim.DESKTOP-F47HO5G\Documents\UnityProject\botr\Library\PackageCache\com.unity.entities@bfeb4734bd\Unity.Entities\ScriptBehaviourUpdateOrder.cs:333
at (wrapper runtime-invoke) object.runtime_invoke_void__this
(object,intptr,intptr,intptr) [0x00020] in <695d1cc93cca45069c528c15c9fdd749>:0

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

Received signal SIGSEGV
Stack trace:
0x00007ff76e0062f9 (Unity) MemoryProfiler::UnregisterAllocation
0x00007ff76d7998eb (Unity) MemoryManager::RegisterDeallocation
0x00007ff76d795c56 (Unity) MemoryManager::smile:eallocate
0x00007ff76d7a7b8a (Unity) free_alloc_internal
0x00007ff76e9fe915 (Unity) UnsafeUtility::Free
0x00007ff76e8918e3 (Unity) UnsafeUtility_CUSTOM_Free
0x0000020dd3e7fa0d (Mono JIT Code) (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.UnsafeUtility:Free (void*,Unity.Collections.Allocator)
0x0000020dd2dfd6a3 (Mono JIT Code) [Memory.cs:85] Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.Allocator,long,int)
0x0000020dd3e7f96b (Mono JIT Code) [Memory.cs:26] Unity.Collections.Memory/Unmanaged:Free (void*,Unity.Collections.Allocator)
0x0000020dd2dff47b (Mono JIT Code) [AllocatorManager.cs:438] Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&)
0x0000020dd2dff273 (Mono JIT Code) [AllocatorManager.cs:456] Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&)
0x0000020dd2dff91b (Mono JIT Code) [AllocatorManager.cs:74] Unity.Collections.AllocatorManager:Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*,int,int,int)
0x0000020dd2dff82b (Mono JIT Code) [AllocatorManager.cs:86] Unity.Collections.AllocatorManager:Free (Unity.Collections.AllocatorManager/AllocatorHandle,void*)
0x0000020dd2dff703 (Mono JIT Code) [UnsafeList.cs:303] Unity.Collections.LowLevel.Unsafe.UnsafeList:Realloc (int,int,int)
0x0000020dd2dff5fb (Mono JIT Code) [UnsafeList.cs:319] Unity.Collections.LowLevel.Unsafe.UnsafeList:SetCapacity (int,int,int)
0x0000020dd3e7f77b (Mono JIT Code) [UnsafeList.cs:261] Unity.Collections.LowLevel.Unsafe.UnsafeList:Resize (int,int,int,Unity.Collections.NativeArrayOptions)
0x0000020e5b03c40b (Mono JIT Code) [NativeList.cs:701] Unity.Collections.NativeList1<byte>:Resize (int,Unity.Collections.NativeArrayOptions) 0x0000020e5b057c43 (Mono JIT Code) [HeapString.gen.cs:71] Unity.Collections.HeapString:set_Length (int) 0x0000020e5bbfb803 (Mono JIT Code) [HeapString.gen.cs:99] Unity.Collections.HeapString:TryResize (int,Unity.Collections.NativeArrayOptions) 0x0000020e5bbfb6ab (Mono JIT Code) [FixedStringAppendMethods.cs:326] Unity.Collections.FixedStringMethods:Append<Unity.Collections.HeapString> (Unity.Collections.HeapString&,byte*,int) 0x0000020e5bbfc183 (Mono JIT Code) [FixedStringAppendMethods.cs:290] Unity.Collections.FixedStringMethods:Append<Unity.Collections.HeapString, Unity.Collections.FixedString512> (Unity.Collections.HeapString&,Unity.Collections.FixedString512&) 0x0000020e5bbfae53 (Mono JIT Code) [GhostStatsCollectionSystem.cs:96] Unity.NetCode.GhostStatsCollectionSystem:SetGhostNames (Unity.Collections.NativeList1<Unity.Collections.FixedString128>,Unity.Collections.NativeList`1<Unity.Collections.FixedString512>)
0x0000020e5b2548eb (Mono JIT Code) [GhostCollectionSystem.cs:362] Unity.NetCode.GhostCollectionSystem:OnUpdate ()
0x0000020e6402d7ef (Mono JIT Code) [SystemBase.cs:401] Unity.Entities.SystemBase:Update ()
0x0000020e6402a098 (Mono JIT Code) [ComponentSystemGroup.cs:474] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
0x0000020e64029af3 (Mono JIT Code) [ComponentSystemGroup.cs:418] Unity.Entities.ComponentSystemGroup:OnUpdate ()
0x0000020e64028cfe (Mono JIT Code) [ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000020e6402a098 (Mono JIT Code) [ComponentSystemGroup.cs:474] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
0x0000020e64029af3 (Mono JIT Code) [ComponentSystemGroup.cs:418] Unity.Entities.ComponentSystemGroup:OnUpdate ()
0x0000020e5b228b73 (Mono JIT Code) [ServerSimulationSystemGroup.cs:76] Unity.NetCode.ServerSimulationSystemGroup:OnUpdate ()
0x0000020e64028cfe (Mono JIT Code) [ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000020e6402a098 (Mono JIT Code) [ComponentSystemGroup.cs:474] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
0x0000020e64029af3 (Mono JIT Code) [ComponentSystemGroup.cs:418] Unity.Entities.ComponentSystemGroup:OnUpdate ()
0x0000020e64028cfe (Mono JIT Code) [ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000020e6402a098 (Mono JIT Code) [ComponentSystemGroup.cs:474] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
0x0000020e64029af3 (Mono JIT Code) [ComponentSystemGroup.cs:418] Unity.Entities.ComponentSystemGroup:OnUpdate ()
0x0000020e64028cfe (Mono JIT Code) [ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
0x0000020e64028aed (Mono JIT Code) [ScriptBehaviourUpdateOrder.cs:335] Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper:TriggerUpdate ()
0x0000020daad1d4a0 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ff92e68e630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke
0x00007ff92e612ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ff92e61bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff76e6c9464 (Unity) scripting_method_invoke
0x00007ff76e6c1db5 (Unity) ScriptingInvocation::Invoke
0x00007ff76df8c4a5 (Unity) ExecutePlayerLoop
0x00007ff76df8c4c3 (Unity) ExecutePlayerLoop
0x00007ff76df932f9 (Unity) PlayerLoop
0x00007ff76f3d9381 (Unity) PlayerLoopController::UpdateScene
0x00007ff76f3d7016 (Unity) Application::TickTimer
0x00007ff76fd4ff81 (Unity) MainMessageLoop
0x00007ff76fd53fc1 (Unity) WinMain
0x00007ff771b89526 (Unity) __scrt_common_main_seh
0x00007ff9ae2b7034 (KERNEL32) BaseThreadInitThunk
0x00007ff9afe62651 (ntdll) RtlUserThreadStart

Using your version it just crash as soon as the string get resized. Is very low level (like the allocator is corrupted)). I’ll check later. As work around, could you please try to allocate an insane large string buffer, like 4MB? so no need to resize probably.
Is just a test to verify the GC spike.