Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug Leak in BatchRendererGroup.InvalidateStaleBatches

Discussion in 'Graphics for ECS' started by ST_KM, Feb 7, 2024.

  1. ST_KM

    ST_KM

    Joined:
    Mar 11, 2021
    Posts:
    1
    In our project, units fight in a small arena. Units are often destroyed and instantiated again.

    We noticed that the running time of
    linearly increases from 0.05 ms to almost 7 ms over 30 minutes of play, this causes a significant drop of FPS. Reloading the scene along with the destruction of all entities, including prefabs from which units are instantiated, does not reduce the running time of InvalidateStaleBatches. Only restarting the game helps (play mode exit / play mode enter).

    Using Unity 2022.3.15f, Entities/Entities graphics 1.2.0-pre.4, URP 14.0.9.
    Also tested: Unity 2022.3.19f, Entities/Entities graphics 1.2.0-pre.6, URP 14.0.10. The problem persists.

    This is what the profiler looks like after reloading the scene after 30 minutes of play:
    profiler-InvalidateStaleBatches.png

    During the analysis, it was discovered that there was no call to m_ThreadedBatchContext.RemoveBatch in EntitiesGraphicsSystem, which, logically, should be a pair to m_ThreadedBatchContext.AddBatch.

    We added this line into Unity.Entities.Graphics/EntitiesGraphicsSystem.cs at the end of the method RemoveBatch:
    Code (CSharp):
    1. private void RemoveBatch(int batchIndex)
    2. {
    3.     /// existing code
    4.  
    5.     m_ThreadedBatchContext.RemoveBatch(new BatchID { value = (uint) batchIndex });
    6. }
    This solves the problem: the running time of InvalidateStaleBatches no longer goes above 0.02 ms. However, no new problems were discovered.
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    352
    Thank you for the analysis and the suggested fix! This certainly looks like a bug slipped in.