TrueSyncManager.FixedUpdate() - lockstep.Update() - insane GC allocation and cpu usage

https://i.imgur.com/x1bzu6V.png



I finally broken down all of the random out of place memory allocation in my project.... what's left is TrueSync eating 7 megs a frame and taking 450ms....

You can see by this breakdown... its happening inside of FixedUpdate() - but not in the sub components that are being called by TrueSync into my code.

... I have no idea how to handle this, I can't even begin to diagnose where the memory is going. ;x

Comments

  • the entire contents of OnStepUpdate() are instrumented... so its not slipping through the cracks here


    void OnStepUpdate(List allInputData) {
    time += lockedTimeStep;

    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate()");

    if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY) {
    CheckGameObjectsSafeMap();
    }
    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate() - A");
    TrueSyncInput.SetAllInputs(null);

    for (int index = 0, length = generalBehaviours.Count; index < length; index++) {
    TrueSyncManagedBehaviour bh = generalBehaviours[index];

    if (bh != null && !bh.disabled) {
    bh.OnPreSyncedUpdate();
    instance.scheduler.UpdateAllCoroutines();
    }
    }
    UnityEngine.Profiling.Profiler.EndSample();
    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate() - B");

    for (int index = 0, length = allInputData.Count; index < length; index++) {
    InputDataBase playerInputData = allInputData[index];

    if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID)) {
    List managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++) {
    TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

    if (bh != null && !bh.disabled) {
    bh.OnPreSyncedUpdate();
    instance.scheduler.UpdateAllCoroutines();
    }
    }
    }
    }

    UnityEngine.Profiling.Profiler.EndSample();
    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate() - C");
    TrueSyncInput.SetAllInputs(allInputData);

    TrueSyncInput.CurrentSimulationData = null;
    for (int index = 0, length = generalBehaviours.Count; index < length; index++) {
    TrueSyncManagedBehaviour bh = generalBehaviours[index];


    if (bh != null && !bh.disabled) {
    UnityEngine.Profiling.Profiler.BeginSample(bh.trueSyncBehavior.ToString());
    bh.OnSyncedUpdate();
    instance.scheduler.UpdateAllCoroutines();
    UnityEngine.Profiling.Profiler.EndSample();
    }
    }

    UnityEngine.Profiling.Profiler.EndSample();
    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate() - D");
    for (int index = 0, length = allInputData.Count; index < length; index++) {
    InputDataBase playerInputData = allInputData[index];

    if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID)) {
    TrueSyncInput.CurrentSimulationData = (InputData) playerInputData;

    List managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++) {
    TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

    if (bh != null && !bh.disabled) {
    bh.OnSyncedUpdate();
    instance.scheduler.UpdateAllCoroutines();
    }
    }
    }

    TrueSyncInput.CurrentSimulationData = null;
    }

    UnityEngine.Profiling.Profiler.EndSample();
    UnityEngine.Profiling.Profiler.BeginSample("TrueSyncManager.OnStepUpdate() - E");
    CheckQueuedBehaviours();
    UnityEngine.Profiling.Profiler.EndSample();

    UnityEngine.Profiling.Profiler.EndSample();

    }
  • Since you will inevitably ask "how many objects are in the scene"

    There are less than 20 true sync objects.

    https://i.imgur.com/GrqTil1.png



    Each entity has 8 sensors, 1 rectangle and 1 circle Body attached to them.


  • UPDATE!

    Fixed a bunch of bad allocations on my end, increasing the game FPS to 50... however, it still down spikes to 20 fps - and this looks like the culprit. Any insights on your end?
  • Latest update, it turns out that these properties:

    body.CollisionCategories = TrueSync.Physics2D.Category.Sensors;
    body.CollidesWith = TrueSync.Physics2D.Category.AllMinusSensors;

    Are just like the IsSensor property - they need to be set AFTER the fixtures or created - or the value you set are ignored. I'm still having small performance losses but now I'm up from 20 FPS to 50-60 FPS! Hurrah!
  • Humm, great catch again @Xelnath, after the core update we should revisit more these physics, mainly the 2D one that is more stable.