Search Unity

Feedback Entities system causes GC allocations every frame in the player - performance by default?

Discussion in 'Entity Component System' started by Xarbrough, Jul 17, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I'm using the Unity 2D Animation package which also uses some parts of the entities system. I've noticed that the call to
    PresentationSystemGroup.UpdateFunction
    allocates garbage every frame when running on the Nintendo Switch player (and in the editor and standalone). I've made sure to enable Burst and disable Leak Detection.

    PresentationSystemGroup-GC-Alloc_Editor.PNG PresentationSystemGroup-GC-Alloc_Player.PNG

    My team and I agree that these allocations should not happen every frame when developing for mobile and console platforms, so I've reported a bug. However, the bug was closed with QA responding: "Our developers suggest the impact on performance should not be noticeable if Leak Detection is turned off." And added that I could try the new Incremental Garbage Collection feature.

    I do value that QA is responsive and I understand if there may be other higher priority issues at the moment, however, I'm worried, that this means Unity developers are suddenly ok with allocating garbage every frame.

    Please stick to your promise of "performance by default". Allocating garbage and slowly churning away at the heap is definitely not performance by default, it's sloppy. Please correct me if I'm wrong, but I don't see any reason why it wouldn't be possible to cache whatever is causing these allocations every frame and only allocate once.
    UpdateFunction.Invoke
    looks like a delegate invocation to me and delegates can be cached and reused. If they receive parameters, it's possible to store them in a buffer outside of the delegate to avoid additional boxing, etc.

    Also, using the incremental garbage collector is only a workaround for an issue that should be fixed at the root. Of course, it's a nice feature to shorten development time if we as game developers can get away with a little less optimized code, but the Unity engine framework needs to be rock solid in this regard and this means no allocations every frame.

    Thank you for listening! :)
     
    Last edited: Mar 8, 2021
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    GC allocations are in fact violating performance by default principles we hold ourselves accountable for DOTS packages. There might be temporary reasons why that is the case but for sure before the package becomes 1.0 they need to be gone.

    I'll follow up with the team.
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    That's great news, thank you! I totally understand if there are temporary issues or simply bugs and priority conflicts.
     
  4. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    On it. GC should not happen. Please stay tuned.
     
  5. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    This thread makes me so so happy. Much love for unity team right now.
     
    Julian_Nementic and Xarbrough like this.
  6. tommox86

    tommox86

    Joined:
    Apr 30, 2015
    Posts:
    88
    has this been fixed or is there a setting i need to implement. aparrant in unity 2020.2.6f1 latest urp, entities hybrid renderer v2
     
    Mockarutan likes this.