Search Unity

No vsync slower than vsync every frame?

Discussion in 'General Graphics' started by jefferytitan, Feb 8, 2015.

  1. jefferytitan

    jefferytitan

    Joined:
    Jul 19, 2012
    Posts:
    88
    For some reason when I switch to lower quaity levels my game runs slower (from approx 60fps to approx 35fps). I experimented and it's definitely the vsync setting. I thought that no vsync was meant to run the fastest because it doesn't wait at all. Or could this be because I was running it in the Unity Editor?

    Thanks in advance,
    JT
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct. No vsync will always run at least as fast as vsync, if all other settings are the same.

    --Eric
     
    jefferytitan likes this.
  3. jefferytitan

    jefferytitan

    Joined:
    Jul 19, 2012
    Posts:
    88
    Okay, thanks for confirming my thoughts. So the question is... why is it in practice slower for me with no vsync? Both the editor framerate and custom measured framerate confirm it. Are there perhaps other settings which are ignored or used differently depending upon the vsync setting?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Perhaps your fps measurement tool is simply broken? There is no possibility of anything being slower just because vsync is off. Perhaps you're spawning things and aren't using a very good timer, so when vsync is off, it spawns more than it can handle?

    Regardless, fairly sure the problem is your own code.
     
    theANMATOR2b likes this.
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you 100% sure that's the only difference? Don't change quality settings, just toggle vsync.

    --Eric
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    or toggle it on / off in code:

    QualitySettings.vSyncCount = 0; //or 1
     
  7. jefferytitan

    jefferytitan

    Joined:
    Jul 19, 2012
    Posts:
    88
    That is literally the only difference. I changed the vsync setting in the editor while the game was running, back and forth a few times. Even with the game paused so the majority of things don't run.

    One thing I do find strange is that when vsync is set to every frame the reported framerate (by both Unity and my custom code) can go higher than the monitor refresh rate. That sounds wrong to me...
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's the opposite of what happens with vsync.

    --Eric
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Possibly you have custom driver settings?
     
    jefferytitan likes this.
  10. jefferytitan

    jefferytitan

    Joined:
    Jul 19, 2012
    Posts:
    88
    I totally agree, but that's what I'm seeing. I think firstly I'll test it on a build... the Unity Editor does weird things to performance sometimes. If that doesn't work I'll look into the driver settings.
     
  11. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Do you perhaps have a lot of code running in an update function? when the vsync is off, the update function will, if I understand it right, run as often as possible, which may use more CPU resources, and perhaps drown out some other parts of the system? Try putting all code in fixedupdate and see if it changes?
     
  12. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    158
    Same issue here. The problem happens on multiple computers, and both within the editor and with builds.
    I made you a screenshot which shows the difference in the Profiler between v-sync (red, fast) and no v-sync (cyan, slow), switched manually. It seems that in the slow "Don't sync" mode, The CPU spends most of the time (about 0.18 sec per frame!) in "WaitForTargetFPS". VSync.jpg
     
  13. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    158
    Note: I force Unity to use DirectX 12 (otherwise the editor slows sometimes down to about 4 fps). I've the impression that the v-sync bug doesn't appear in DirectX 11, but it's hard to test with my editor problems.
     
  14. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Do you by chance have a reference to Application.targetFrameRate in your code? When vsync is on this is ignored, but it wouldn't be with vsync off. It's hard to believe you'd have this in your code, but it's the only thing I can personally think of that would cause it to run slower with vsync off.
     
  15. merenpta

    merenpta

    Joined:
    Feb 27, 2016
    Posts:
    3
    * Note: English translated into Google
    I also encountered this problem and could not understand it.
    So I tried and found the cause for several hours.

    The cause was in Application.targetFrameRate.
    If VSync is on, its value is ignored.
    If VSync is off, it affects the frame.
    The default value is -1, which works differently depending on the platform.
    It seems that there is no limit on the PC.
    But on mobile, it works at 30 fps.
    So, when you turn off VSync on mobile, it happens to be slow.

    Add the following sources.
    Application.targetFrameRate = 60;
     
    Last edited: Mar 16, 2019
  16. gamrDev

    gamrDev

    Joined:
    Jul 7, 2017
    Posts:
    12
    I too have this problem. If I turn off only vsync the player movement slows down but using "Every V Blank" option makes it run normally and using "Every Second V Blank" makes it run even faster.
    I tried @imaginaryhuman solution about moving code from Update to FixedUpdate and it solved but I want to know why it slowed when using update + no vsync and not when using FixedUpdate + "any vsync setting"
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That just means you made your movement framerate-dependent. Fix your code, don't put it in FixedUpdate (which is only for physics).

    --Eric