Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Point graph (Aron Granberg A*) suddenly allocates lots of garbage on scan after switch to URP

Discussion in 'Editor & General Support' started by cnio14, Nov 16, 2023.

  1. cnio14

    cnio14

    Joined:
    Jun 19, 2020
    Posts:
    4
    I use Aron Granberg's point graph by manually placing nodes on a 3-dimensional discrete grid, because I need my agent to move forward, back, left, right but also up and down. So far, it works like a charm and I can add nodes at runtime and connect the graph. That, however, until I decided to port my project to URP. Now, whenever a new node is placed and the graph scanned, there's a massive lag spike caused by garbage collection (specifically GC.Collect within Late post processing initiated when the graph is scanned). The weird thing is that this happens even if I have just placed the first ever node of the scene (so there is really nothing to scan or connect to). I should underline the fact that this started happening only after the switch to URP, which to me is still a mystery since the rendering pipeline should have no influence on this. I post a screenshot of the Profiler for further diagnosing.

    The only thing I can think of that is also graph size agnostic would be that somehow the initial search for node candidates (via tag in this case) is taking a very long time.
     

    Attached Files:

  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,407
    What's more likely to be interesting is to check out what's happening here:
    image(1).png
    and how you can reduce the memory allocation needed during that spike. The more memory you allocate, the more the GC has to run and eventually collect.
     
  3. cnio14

    cnio14

    Joined:
    Jun 19, 2020
    Posts:
    4
    Thank you for the response. How can I specifically debug the memory usage to get more information out of this?
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,407
    You can check the Memory Usage graph with it's dark-red-brown line for GC Allocated In Frame to find frames with big allocationsy and then use the CPU Usaged Profile4 module with Deep Profiling and/or Allocation Callstacks turned on, following the GC.Alloc Column in Hierarchy down to where the GC.Alloc samples are that allocation the biggest chunk and see what's causing them
     
  5. cnio14

    cnio14

    Joined:
    Jun 19, 2020
    Posts:
    4
    Ok I found more details here, but I could not really interpret it
    upload_2023-11-16_18-46-48.png
    This is what happens during a memory spike initiated by a full graph scan.
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,407
    The GC.Collect call is unimportant, though you can select it and switch to timeline and check what magenta colored GC.Alloc Samples occured before (and which one occured immediately after it). Those are the calls that lead to it and eventually trigger the GC.Collect. It's like a balloon getting filled with air until it bursts, where the GC.Alloc is the air and the bang of the exploding balloon is the GC.Collect.
     
    Last edited: Nov 16, 2023
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,407
    Also, you can sort the Hierarchy by the GC.Alloc column to find the worst offenders.