[MUSIC PLAYING] When it comes to
performance, there’s some stuff you can
control, and then there’s other stuff that you just have
to be aware of and work around. My name is Colt McAnlis. And CPU frequency scaling is
one of those harsh realities of mobile development that
you can’t control, but can have a significant impact
on your application. See, in order to
conserve battery, Android devices can
reduce the amount of voltage supplied to the CPU. This means that the processor
will draw less energy to execute code, with the
side effect of slowing down your CPU in the process. Essentially, your code
will take longer to run. And this is a very
regular occurrence. Your Android device
is constantly trying to throttle
voltage to the CPU to save as much
energy as possible. The interactive CPU
governor that Android uses constantly checks
the CPU workload to determine if the
frequency can be scaled back or if it needs to be ramped up. The ramifications of such
are a little weird to you, as a developer. Firstly, when the
frequency gets throttled, you’ll notice that normal
operations take longer to execute. So don’t be surprised if,
suddenly, your frame time spikes start to shoot
above 16 milliseconds. And secondly,
changes in frequency take about 20
milliseconds to occur, meaning that if you come right
out of a low-frequency state, the first frame of rendering
may be slower due to the fact that the CPU hasn’t had
a chance to ramp up yet. In general, you need
to remember that this is working as intended. A battery is everything
on mobile development. And to the Android system,
it does a really good job of balancing processing
speed versus battery drain on your
behalf, so you really don’t need to worry about it. And in fact, there’s
a whole bunch of things it does to
avoid this problem, where performance is
critical, like bringing the frequency all the way up
as soon as the user touches the screen. But other times, like if
you’re using a service or responding to an event,
you can see these issues manifest themselves. Just keep in mind that if you
start seeing frame rate spikes or things taking longer than
they should be for no reason, that frequency use scaling
could be the culprit. To confirm this, you can
run a Systrace profile, enabling the CPU frequency flag. You’ll notice a
nice bar at the top that details what the
current frequency values are, so you can see
how, overall, it’s impacting your performance. And performance is all
about understanding what the hardware is doing
and how your code should react accordingly. In this case, there’s not
really much you can do. But in all the other cases,
there’s a ton of things that you can work on. So make sure you check out the
rest of the Android Performance Patterns videos. And don’t forget to join our
Google+ community for other great tips and tricks. So keep calm, profile your
code, and always remember, perf matters. [MUSIC PLAYING]

CPU Frequency Scaling. (Android Performance Patterns Season 4 ep17)
Tagged on:                                                                                                                     

7 thoughts on “CPU Frequency Scaling. (Android Performance Patterns Season 4 ep17)

  • January 12, 2016 at 4:37 am
    Permalink

    When is the next series coming ?

    Reply
  • February 2, 2016 at 6:26 pm
    Permalink

    @0:24 it should be MHz and not mhz…

    Reply
  • February 2, 2016 at 6:57 pm
    Permalink

    I like that the app you're running systrace on is called "com.android.janktown"

    Reply
  • February 2, 2016 at 11:40 pm
    Permalink

    Wondering if these videos are being added to the Udemy Android Performance Course automatically.

    Reply
  • February 3, 2016 at 12:27 am
    Permalink

    me like all his videos

    Reply
  • August 24, 2016 at 8:06 am
    Permalink

    1:14 it's Frame Time not Farme Time 😀

    Reply
  • November 29, 2018 at 10:08 pm
    Permalink

    Mine 1,4 gz cpu never see 1.4 gz while lag

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *