Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Profiler issues 2019.3.3 vsync spikes?

Discussion in 'General Graphics' started by lejean, Mar 5, 2020.

  1. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    Just upgraded my project from 2019.1 to 2019.3.3 and the profiler keeps showing my game running at 60 fps.
    Vsync is off in settings and the Nvidia control panel is application controlled.
    This doesn't happen when I open it in 2019.1.

    Aside from that I'm getting these consistent editor loop spikes that give no explanation aside from the time jumping from 8 ms to 38 ms.

    Any ideas?

    profiler.png
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    Hi,
    Those spikes come from the ProfilerWindow repainting (at a lower frame rate, so that there are frames in-between that are less impacted by the Editor running on the same main thread as the game in playmode).
    Please note that Profiling Playmode is not ideal to figure out your game's performance and profiling a built player gives way more relevant and cleaner data.

    As to the 60fps cap: In 2019.3 the Game View's Aspect ratio drop-down menu contains a VSync (Game view only) toggle, so that's probably on and why you're seeing a difference between 19.1 and 19.3
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    Also, If you ever want to get more info about what took time in the EditorLoop, you can switch the target from Playmode to Editor (or turn on Editor Profiling in versions Pre-2019.3).
     
  4. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    Thanks for the reply!

    I Just checked and the Vsync toggle is off.
    This also happens in a build btw, profiler also shows 60 FPS with Semaphore.waitforsignal spikes

    build profiler.png
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    Are you setting Application.targetFrameRate?
    What platform did you build for?

    As for the Semaphore, these samples are explained in the CPU Profiler Manual. The short of it is, your main thread is waiting for the Rendering thread to finish presenting the frame, which might be down to VSync but you'd need to check Timeline view to see that.
     
  6. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    It's a windows build, and as far as I know I'm not setting Application.targetFrameRate , I did a debug log for the targetFrameRate in Start in some script to check if it was set somewhere, but it was -1.

    When I check the timeline it's Gfx.presentframe taking up most time.

    build timeline.png

    But in the end I updated my project from 2019.1 where this wasn't happening, and I didn't really change anything.
     
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    yeah, unless you have some heavy GPU work to do, those 29ms for present make no sense. If that was down to VSync, it could've ended after 16ms.

    What Graphics backend are you using? Have you tried GPU profiling that (potentially with a GPU hardware vendor's Profiler)?
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    Also, other applications on your Machine might impact the GPU timings so maybe you'd want to profile the game running on a different machine than your Unity Editor, or close the Unity Editor and gather some profiler data via the Profiler.enableBinaryLog API, then load that data in afterwards.
     
  9. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    Dnno even on an empty scene the profiler shows the same, constant 60 FPS with spikes.
    It's all from the "Others" section in the profiler.

    I do use a multi monitor setup where I put some unity tabs on the other window which seems to be an issue.
    I just did a reset on the unity editor layout and that seemed to reset the profiler back to showing the 200 FPS average.
     
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    If you're profiling in the Editor, that's likely the Profiler Window. Others in the Editor is mostly taken up by Editor stuff. For more details you'd have to switch from Playmode to Editor, but if you want to see more accurate timings for your game, you should profile a build.
     
  11. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    K so I seem to have found the perpetrator.

    My videocard is connected to 2 monitors and a TV with a long HDMI cable.
    The cloned monitor with the TV is what's causing the FPS cap.
    When I unplug the HDMI cable I get 200+ FPS.

    Not sure why but something is causing a forced vsync of some kind.
     
    Last edited: Mar 10, 2020
  12. Lopost

    Lopost

    Joined:
    Aug 10, 2017
    Posts:
    5
    Have you solved it? Because I have the exact same problem...
     
    NSokolovskyi likes this.
  13. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Hi! I meet the same problem. Do you have any idea about it?
    QQ截图20210611130642.png QQ截图20210611130936.png
     
  14. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    Doesn't look like the Profiler Window repainting and it's happening under the GarbageCollector category so it's not the same issue but related to Garbage Collection, i.e. the Editor UI, here the SceneView, happened to request a new allocation for managed memory when there was not enough of that left, so Garbage was collected.

    To address that, you should check out what all was allocating managed memory (GC.Alloc Samples) look at the worst offenders and see if you can reduce those. Check out the Call Stacks profiling option for help on that search.

    Some of that might come from the normal running of Unity's editor, some might come from plugins, or your own assets and some might come from your game. Addressing allocations in your game code can help final performance of your game too, Editor only allocations will "only" trip up your editor occasionally but if that's a lot, it may be worth to examine those. If it comes from the base Editor code, there's not much you can do there besides reporting bugs on the places that allocate unreasonably much.

    You may also want to check if switching to Incremental GC helps.
     
    Last edited: Jun 14, 2021
  15. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thanks for your help!
     
    MartinTilo likes this.
  16. vignesh211

    vignesh211

    Joined:
    Feb 8, 2019
    Posts:
    13
    Not sure though. Your monitor is capable of forcing v-sync to match the game fps with its refresh rate