Search Unity

Deep Profiling IMPROVES framerate 4x. How to ship this benefit?

Discussion in 'Editor & General Support' started by NNSkelly, Oct 8, 2020.

  1. NNSkelly

    NNSkelly

    Joined:
    Nov 16, 2015
    Posts:
    35
    I'm engaged with a workload involving a number of ComputeShader dispatches to crunch data that was abysmally slow (read: 10-15fps) to iterate over on CPU.
    After the latest round of tweaks, I was getting up to 200fps with 1 data source, and, not entirely unexpectedly, closer to 30fps with 3 data sources going in parallel.
    Subsequent runs without changing anything, I began seeing drops to around 15fps average. No memory creep or anything obvious. So of course I turn on deep profiling, expecting to soak a big performance hit just to see where the time is going (most likely bulk data copy, just wanted to track down the biggest offender).

    Turning on Deep Profile (stopping & re-running the scene)... increased fps to 60 and revealed data copy times around what I expected- 7-8ms a pop, 20ms total/frame.
    Turning off Deep Profile (stopping & re-running the scene) drops fps back to 15, with the displayed outermost call around the data ops increasing to previously observed levels in excess of 60ms/frame.

    This is so unusual that it has got to be indicative of SOME fundamental caveat of how data is managed under the hood, and which I might be able to capture the benefits of if I knew what locks/brakes to apply where. Any ideas?

    Edit: no, it's not 20-60ms processing every single frame; that's obviously contradictory with the ms threshold needed to achieve 60fps at all. The sensors don't deliver data every frame. But the deep profiler seems to be the difference between bursts/spikes every sensor-data frame which average to a stats-window-reported higher framerate vs a literal saturated wall of CPU time where the previous sensor data can't get processed until, I'm guessing, after the next sensor payload is queued.
     
    Last edited: Oct 8, 2020
  2. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    250
    Maybe the overall speed of your code decreases and thus the cpu sends data to the computer shader less often? Just a guess. Another guess would be the device throttling due to thermals. So I would reduce the load / amount of work the shader does per frame and try if the helps your problem
     
    PraetorBlue likes this.
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Please, do not rely on the frame rate in the Stats window. More details on that here and here.

    And I'm not entirely sure I managed to follow what is going on when but yes, this sounds like the thing that changes with Deep Profiling is the interval at which this work is getting processed and then looking at the Stats Window, where EditorLoop Main thread times are calculated out will be entirely the wrong place to look at, because threads/GPU can continue working on your PlayerLoop issued workloads while the Editor does something else, making that FPS metric in there more than just "fuzzy".