Search Unity

[SOLVED] Lagging in Physics at high Update frame rates

Discussion in 'Physics' started by jamespaterson, Sep 20, 2020.

  1. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    398
    Hi All,

    I have experienced some interesting behaviour whilst attempting to optimize my game and I was wondering if anyone had the same experience. Essentially, at the moment I have removed the FPS cap for the application (I have set Application.targetFrameRate = 300), however fixed update is set to a fixed time of 50fps (0.02 seconds I believe).

    During testing, with vsync switched off often my game will hit 150FPS continuously, however occasionally (say once every ten seconds, but seemingly randomly) it will lag for ~1 of a second down to, say, 45FPS. Looking at the profiler output it seems that Physics processing is kicking in.

    If I set Application.targetFrameRate = 60 then the lag does not occur in testing. I have tried turning of auto sync transforms and running a manual sync in LateUpdate after each frame.

    I am wondering if there is some sort of scenario where if the Update FPS is much higher than the Physics FPS the system occasionally needs to do an expensive operation to "catch up"? Looking at the task manager whilst the "catch up" is occurring then GPU usage is right now but CPU stays high.

    Thanks in advance for any help on this!
     
  2. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    398
    hi all, so kind of answering my own question. I think I am reasonably satisfied as to the cause of this issue.
    I believe the root of it all is thermal throttling of the CPU (and possibly GPU) on my PC.

    I am using a laptop. I tried many, many different approaches to try and isolate the cause of the problem, including running physics simulation manually etc. In the end I managed to get a screenshot of the behaviour in case this might help anyone else. You can see the profiler which is generally showing nice high FPS, but with a ~1 second block of slow down. An analysis of these regions shows pretty much everything has slowed down. The screenshot itself was taken in the middle of a second slow-down period which has not ended yet. In the game window you can see the graphy bar with FPS hitting the floor for a little period. To the left is CPU-Z which shows the CPU down to 800Mhz (from ~3Ghz) underneath, speedfan shows a bunch of hot components.

    From now on I will use a dedicated laptop cooler during benchmarking.