Search Unity

ELI5 How does DOTS improve battery life?

Discussion in 'Entity Component System' started by itsarjunsinh, Feb 5, 2020.

  1. itsarjunsinh

    itsarjunsinh

    Joined:
    Nov 9, 2019
    Posts:
    16
    I'm already convinced by DOTS based on it's approach alone but the following claim has me curious.
    "DOTS provides programmers with a convenient sandbox to write safe multithreaded code for massive performance gains, while also optimizing thermal control and battery life on players’ mobile devices."

    ELI5 : How does DOTS lead to better temps and battery life?

    Secondly, in Getting started with DOTS: Scripting Pong (Tutorial), @Mike-Geig stated that DOTS is overkill for (simple games like) Pong and it's (programmatically) faster to just run the code on the main thread. Is there a case for taking a performance hit for lower temps and better battery life?
     
  2. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    125
    DOTS runs super fast which means your CPU doesn't have to work as hard so it keeps power consumption low.
    Of course if you push DOTS to its limits and have 100,000 Entities running around then no matter how optimized the code is the CPU will be working hard and consuming power.
     
  3. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Basically the CPU can do the same amount of work in a shorter time, leaving bigger "idle gaps" where it doesn't consume power.
     
  4. thebanjomatic

    thebanjomatic

    Joined:
    Nov 13, 2016
    Posts:
    36
    Probably not in this case. What Mike was alluding to is that there is a small overhead to scheduling a job. This shows up both in terms of some amount of extra code that needs to run on the main thread, and some work by each thread to figure out what to work on next and all the required synchronization. When you are only looping over two items and doing a few math operations the overhead of scheduling is going to be larger than the actual job time, so you are doing more work on the cpu and it also takes more time.

    You are also potentially waking up a background thread on top of that which isn't great from a power perspective as it would be running on a separate core from the main thread that might have been in a low power state. The idea as @siggigg stated above is to get the work done as fast as possible so that there is more idle time between frames such that the cores can be powered down while waiting for the next frame.

    There is, however, another aspect of this which I believe comes down to minimizing transitions between power states.

    Basically the longer a core sits idle, it has a chance of hitting a deeper power state. If its only idle for brief periods of time, it might just get clocked down a bit, but if its idle for longer, the core might enter a deeper sleep state. (See c-states for more information).

    Its a subtle distinction, but you could have two different workflows; In scenario 1, you have 100 jobs executing up front and then waiting for 10ms, and in scenario 2 you have 100 jobs executing over the duration of the frame. The aggregate CPU time and idle time is roughly the same in both cases, but the best case is scenario 1, as the cpu gets all the work done while in full power, and then gives the cpu an opportunity to power down deeper.
     
    itsarjunsinh likes this.
  5. itsarjunsinh

    itsarjunsinh

    Joined:
    Nov 9, 2019
    Posts:
    16
    There won't be an overhead if I program the DOTS way (separate data and system classes) but run the system classes on the main thread via "Run()", right? I take it a balance is necessary when creating simpler games targeting phones or low-end computers. Thanks for answering.
     
    thebanjomatic likes this.