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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Why doesn't Unity use the available resources?

Discussion in 'Editor & General Support' started by Konyak, Feb 3, 2021.

  1. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    Even running from the editor or from build, I noticed that Unity doesn’t take advantage of a third of the available performance. There is no limitations are set in.
    Why not go up the fps when still have plenty of computing power? What could be the problem? Is there a setting I don't know or a technique I should have been paying attention to?

    I would be very grateful if someone could help me.

    (Sorry for my bad english.)

    UnityLowCpuUsage.jpg
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    First, the Stats window is not a very reliable measure of performance.

    Second - do you have Application.targetFramerate set, or is VSync enabled? What is the refresh rate of your monitor?
     
  3. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    It's a VR project, so the target framerate 90 fps, but
    This is also the case with other monitoring software, not just in the Stats window.

    It is a VR project, so the target framerate is 90 fps. But with testing intent, I raised it to 900 to not limit anything. Some test scenes go at 900 fps and use the hardware at 70-80%. I don’t understand what might be limiting the use of resources.
    I test it on a monitor because it is not limited. The VR headset runs only at the appropriate fps.
    V-sync is off, so it can go above 60 fps.

    The 70 fps shown in the picture is a pretty good value, often dropping to 30-40 so that neither the CPU nor the GPU load goes up. They sit there around 30%.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    Is that CPU measurement from Windows taking into account the multiple cores of your CPU? Maybe just a single core is at 100% utilization, and since Unity is single-threaded unless you are doing something special, that is as fast as it can go.
     
  5. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    I checked, all the cores are going at pretty much the same performance.
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    Well, the only advice I can give at this point is use the Profiler and try to see what the bottleneck seems to be. That should be step 1 for any performance/framerate issue.
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Unity has improved its multithreading, but there is still a single main thread. If that main thread gets maxed out, then you're not going above whatever FPS at which that occurs. Also, if you're hitting your specified target frame rate, then it isn't going to go any higher than that because you've specifically told it not to. That's the whole point of setting a target frame rate - you're basically telling Unity to use all the performance necessary to hit that frame rate but do not use any more than that.

    If you want better multi core usage than you're seeing, even if you remove any target frame rate, you need to either implement more of your game in your own custom threads yourself, or switch over to the alternative DOTS/ECS system.
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    There's also the Jobs system which supposedly can be used independently of ECS.
     
    Joe-Censored likes this.
  9. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    All CPU Cores are going at pretty much the same load, so there is no maxed core.

    As I said before:
    "It is a VR project, so the target framerate is 90 fps. But with testing intent, I raised it to 900 to not limit anything. Some test scenes go at 900 fps and use the hardware at 70-80%. I don’t understand what might be limiting the use of resources. I test it on a monitor because it is not limited. The VR headset runs only at the appropriate fps. V-sync is off, so it can go above 60 fps.

    The 70 fps shown in the picture is a pretty good value, often dropping to 30-40 so that neither the CPU nor the GPU load goes up. They sit there around 30%."
     
  10. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    Interestingly: when I turn off dynamic shadows, fps goes up and the load goes down by 5%.
    (Fps is still far from the target framerate.)
     
  11. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    Just another example:
    UnityLowCpuUsage2.png

    This is the build, and the highest CPU core usage is at 62%, 5 core under 50%, and 3 are between 50% and 60%.
    GPU sits at 30-32%.

    This game is heavily phisycs based, due to the many cars. The profiler show that the 45% of time is phisycs and there is nothing wrong with it, but why doesn't Unity use the available resources?
    I tried everything I could, but nothing helped.

    Can anyone help me please?
    (Sorry for my bad english.)
     
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,161
    How does the profiler look like in Timeline view? Are most threads Idle for about 50% of the time? Does the main thread wait on the GPU or render thread for longer durations? Then those threads is not maxing out the core's they are running on but are just sleeping, not consuming any power, because they have nothing to do. There are scheduling dependencies like this that mean that your game isn't fully active on all cores at full throttle all the time and that's pretty normal. *

    There's also the question of how much computation time your code can actually take up on a core and how much it is just waiting for memory to be loaded into the L1 Cache for it to use. Depending on how your CPU load is calculated, it probably doesn't count time it spends waiting for these cache misses towards the percentage of usage time per frame. A platform/CPU manufacturer's Profiler Tool might be able to give you more precise hardware level info of the on-core/off-site times and time spend on cache misses.

    (* Most software today is incapable of maxing out your CPU on all cores like that, unless it's doing some kind of simple data processing that can easily be split up and multithreaded. The JobSystem, Burst and DOTS in general is Unity's approach to making sure more and more of the complex data processing needed for Applications build with Unity can be split up and multithreaded like this. It's a process you can try to tap into some of that potential already, but it's not yet at a stage where you just flip the switch and boom, all cores run hot.)
     
  13. Konyak

    Konyak

    Joined:
    Nov 21, 2019
    Posts:
    20
    When I turn off hyper threading on the CPU, the load goes up to 90%. (Fps stays the same.)
    So it is likely that hyper threading distorts the measured values.
    Thanks to everyone for their help.