Search Unity

Garbage Collection Constant Lag Spikes?

Discussion in 'Editor & General Support' started by vsnry, Dec 9, 2018.

  1. vsnry

    vsnry

    Joined:
    May 4, 2018
    Posts:
    35
    Hi, I have a procedural voxel terrain which works fine, but suffers from constant framerate drops. I looked at the profiler and it seems to be a garbage collection problem, as you can see in the video it happens constantly at the exact same interval, even when standing still when no chunks are getting created or destroyed. How do I fix this?

    https://i.gyazo.com/af39a92d3bcaa25a99d3009e87cd2ba6.mp4

     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    MartinTilo likes this.
  3. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    The above link is a definitely a good place to start. A few quick thoughts... even though you're not creating the chunks every frame, it wouldn't be much of a stretch to imagine that you might be processing the chunks in some way every frame whether that involves traversing an octree or priority sorting for a grid structure. If you have anything that requires instantiating a new List or Array each frame, maybe see if you can preinstantiate it, and then clear and reuse it each frame instead... and hopefully structs are an option. One more thing... some annoying performance hiccups magically disappear when you compile. I've wasted days at a time on in-editor reoccurring performance hiccups only to discover that they don't actually exist in the wild. Good luck!