Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

GarbageCollector.CollectIncremental 4ms cost every few frames in editor

Discussion in '2019.3 Beta' started by Peter77, Sep 7, 2019.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    I'm testing 2019.3.0b2 with the project attached to Case 1108597 and noticed, while playing the game inside the editor, GarbageCollector.CollectIncremental kicks in every 40 frames with a cost of about 4-5ms.

    My understanding of the incremental GC was that is would spread work across multiple frames to prevent those spikes. Does this sound like an issue to you or is it expected behavior?

    upload_2019-9-7_7-37-51.png
     
    Prodigga likes this.
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Hi,

    Could be either, depending on your project :)

    This is correct - but the GC needs to know how small to break up the work. Now depending on your project setup it will do one of two things:

    1. If you are using frame throttling (either using vSync, or using Application.targetFrameRate), it will look at the time available for each frame and try to budget within the available time for a frame.

    2. If you are not using frame throttling, it will try to budget within GarbageCollector.incrementalTimeSliceNanoseconds - which defaults to 3000000 (3ms).

    Looking at your profiler screenshot, I don't see any synchronization happening, so I assume we are looking at case 2. So the GC should try to take no longer than 3ms by default. In your case you say it's 4-5ms - but note that I wrote _try_ to take. It is not uncommon for the GC to overspend it's budget by 1-2 ms, that's within the margin of expectations.

    So, can you try to either enable vSync (which might make sense anyways if you care about 4ms spikes making your frame rate less smooth), or setting GarbageCollector.incrementalTimeSliceNanoseconds to a lower value, like 1000000?