Search Unity

Question GC - Rendering & Input Module generated garbage

Discussion in 'Editor & General Support' started by M4dR0b, Mar 19, 2021.

  1. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Hi there,

    as of lately I'm getting into trying to generally optimize the generation of garbage.

    I've documented myself a bit more in depth about the argument and results are quite optimistic; build is running smoothly at 60fps, GC Allocs produced by my integrations are minimal and run every now and then just 'cause of player interaction, and GC Collection doesn't shutter the game. "That's great! Huzza!"

    Now, the real deal comes when fiddling with engine stuff:

    Below you can see the standalone build profiled with -deepprofiling (which increases the CPU time probably 'cause of internal component).

    Using
    Unity 2019.3.15
    HDRP 7.3

    Profiler01.png

    Most of the frame time is occupied by the CPU preparing the frame to render. Since the prj has 3 concurrently active cameras it takes quite a while, but that's not a problem.

    What I'd like to understand is this:
    Profiler02.png

    Unity is constantly allocating 289B of garbage each frame, which results in 17,34 KB in 60 frame and ~1MB per minute.
    The 3 RenderLoop in red should be the 3 cameras. With identical setup the 3rd one is not allocating garbage at all, I wonder why. To conclude this section there's that TickRealTimeProbe, which there're none in the scene.

    Another interesting results is whenever the mouse goes hover a UI interactive element, such a button for example:
    Profiler03.png

    I'm wondering if there's something I could do regarding those 2 GC allocating "monsters" without getting too deep like "Write your own SRP" or "Write your own UI system".

    Thanks :)
     
    GuirieSanchez likes this.
  2. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    bump, anyone care to share some arguments?
     
    GuirieSanchez likes this.
  3. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
  4. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Bump, not giving up :p
     
  5. Without knowing anything about your setup, my immediate thought was that you should check your UI event subscriptions. I'm not sure about this, because, well, I know nothing about your project, but there are scenarios when events can generate sometimes substantial garbage upon usage.
    Otherwise, share more about your project and we may be able to help you.
     
  6. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Thanks for the reply, the project I cannot share, an overall description would be: "a 3D scene and a UI panel on second display for monitoring and control, 4 cameras rendering constantly (1 on screen, 2 on small RTs, 1 rendering UI on second display)". Regarding UI is just the behavior of unity internal UI components on Over (buttons, toggle, and the likes). The other garbage is generated by the rendering pipeline, it's hard to pinpoint what exactly is going on, especially since 2 out of 3 identical camera rendering the same things generate garbage, the 3rd does not.
     
  7. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Don't get me wrong, I would gladly accept as an answer "Hey, this is totally normal for Unity to generate a small amount of garbage on its internal components, but is nothing to worry/you can do about it, you are perfectly fine with that amount of garbage", or if somehow there's a way to further reduce GC getting close to 0. Actually, is it even possible to have 0 generated garbage for a project?
     
    Last edited: May 4, 2021