How To Make Firefox Over 40% Faster

If you use Linux on a Laptop, chances are high that you can dramatically improve the responsiveness of all your GUI applications. This tip will work for you if you:

In short, the trick is to disable powernowd and use the ondemand governor instead. How to do this in Ubuntu comes later, let me first show you what this change gets you. In short, you get maximum performance and a longer battery life.

Benchmark

I have a laptop with a Pentium-M that allows frequencies between 600MHz and 1500MHz. Running on 600MHz gives a long battery lifetime and a quiet notebook, on 1500MHz I get good performance. The trick is to switch between the frequencies so that you can have the best of both sides.

This are the rendering times of the CNN site, with different CPU frequency scaling settings. Each measurement was performed 4 times, and the average is show.




Here is an explanation for the graphs:

  1. powersave (600MHz): Since kernel 2.6.9 there are CPU governor in the kernel that allow different frequency scaling behaviour. In the first benchmark the CPU was set to “powersave” which means that only the lowest possible frequency is used. With 600MHz it takes 9.38 seconds processor time to render CNN.com.

  2. performance (1500MHz): The governor “performance” always keeps the CPU at the maximum setting, 3.82 seconds render time is the fastest I can possibly get from of my machine.

  3. powernowd -q -m 3: This one is interesting, here the governor “userspace” was used which means the frequency can be controlled by a userspace application, which in this case was powernowd. The load time is somewhere inbetween the previous two benchmarks, which means that powernowd correctly recognizes that there is a high CPU demand, and switches to the highest frequency. This detection takes quite a bit of time so precious 1.73 seconds are lost compared to what is truly possible with this computer! This is very bad.

  4. ondemand: Finally the glorious “ondemand” governor. This governor switches to the highest frequency if processor usage goes above 80%, and switches back to the lowest frequency where the CPU has less than 80% utilization as soon as possible.

    This is not much different from powernowd, except that it can sample the CPU utilization 25 times per seconds which means it can react in mere milliseconds on a change. Since the governors are kernel modules this does not have the high overhead that a userspace tools like powernowd would have with such a sampling rate. The result speaks for itself, the ondemand governor provides almost exactly the same performance as with constantly running at maximum speed. Not only does it have almost no performance difference to the maximum settings, it is also very good for the battery because it is equaly fast when switching back to lower frequencies.

    For more background information about the algorithm behind the ondemand governor have a look at the paper The Ondemand Governor.

How To Benchmark For Yourself

You do not need anything special for this benchmark, this is how I have done it:

  1. Install the Fasterfox extension, this has a page load timer

  2. Browse to any website (I used CNN since it is a quite complicated site that takes a while to render).

  3. Save the website (File > Save As).

  4. Now enter the name of your saved file into the address bar (e.g. /home/martinus/CNN.html for me). It is important to use the saved file, so that the load measurement contains the raw rendering performance and not how fast you can download.

  5. Wait about 5 seconds, so that you can be sure whatever you use for frequency scaling has switched to the lowest MHz setting.

  6. Press Enter.

  7. Have a look at the timer (lower right corner of firefox) when the page has finished loading.

How To Use Ondemand Governor In Ubuntu Dapper

This is quite simple. See this For a longer description.

  1. Uninstall powernowd

    sudo apt-get remove powernowd

  2. Enable speed stepping (I have a centrino, you might need a different module)

    sudo modprobe speedstep-centrino

  3. Enable the “ondemand” governor

    sudo modprobe cpufreq-ondemand

  4. Switch to the ondemand governor (default is performance). As someone in the comments has pointed out sudo does not work here, so use this:

    sudo bash
    echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    exit

For permanent settings:

  1. Open /etc/modules and add the following lines (if you do not have a centrino chipset you need to exchange speedstep-centrio with something else)

    speedstep-centrino
    cpufreq-ondemand

  2. Install sysfsutils with

    sudo apt-get install sysfsutils

  3. Open /etc/sysfs.conf and add the line

    devices/system/cpu/cpu0/cpufreq/scaling_governor=ondemand

39 thoughts on “How To Make Firefox Over 40% Faster

  1. Pingback: Eli’s Daily Articles » Blog Archive » How To Make Firefox Over 40% Faster

  2. nevertheless it improves firefox’s rendering performance quite a bit. I could not care less if this is a firefox problem or not, everything that makes it faster it is a good thing. The only reason I wrote firefox in the title is that this was the only application where I could measure the improvement accurately. It also improves typically slow appliations like azureus or eclipse a lot.

  3. Pingback: The Independant Penguin » Blog Archive » How To Make Firefox Over 40% Faster

  4. I’ve use this tweak since a month, and it’s a LOT better than powernowd. Another advantage is that you use less power, powernowd seems to ‘stick’ to high frequencies sometimes when there’s absolutely nothing to process. Ondemand switches immediately back to the lowest freq.

  5. FWIW, I don’t think the sudo line is correct. Replace with:
    sudo su -c ‘echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor’

  6. Firefox is the only appliction that you could test?
    wtf?

    you can start any program on your computer preceded by the time command to find out exactly how long that command ran, and you say firefox is the only benchmarkable program?

    Nie try for a dig front-page pot though.

    in a cli, enter:
    time anyprogram

    it will run, exit, and display how long it took.

    Now thats how you benchmark stuff.

  7. You can’t write to /sys with sudo, you need a “real” root account. I made a small init.d-script to permanently set the ondemand governor at boot time.

  8. permission denied….

    to perform certain actions, such as writing to /sys, you will need to use a traditional root account rather than sudo.

  9. What about the “conservative” governor? I’d love to see that one in your little graph. I’ve used that one for a while to try to maximize battery even more and reduce the overhead of switching speeds.

  10. Pingback: Dinges’ Blog » Blog Archive » La Cienega Just Smiled

  11. Does the enable speed stepping module part apply to AMDs too or just Centrino; I think AMD has a thing called powernow. Either way what would be modprobed for an Athlon 64?

  12. Innocent question – what impact on the battery does the fact that you are looking at the cpu useage 25 times every second have?

  13. Pingback: Austoon Daily » How To Make Firefox Over 40% Faster

  14. How can I determine what kind of cpu I have, and then how to know what modprove to use. /proc/cpuinfo just says Pentium III (Coppermine).

  15. For those criticizing this guy for using Firefox instead of other apps — Firefox is *exactly* the kind of application that benefits from his suggestsions. It’s mostly idle, but has very bursty high-CPU needs. Apps like mpeg players won’t benefit – since they’re never idle even the user mode CPU switching will stay at a nice fast CPU speed. Apps like text editors won’t benefit because they never generate large bursts of CPU needs. This guys’s recommendation really benefits FireFox and some graphics editing programs the most; so IMHO it’s good that it’s positioned as a firefox-optimization article.

  16. anonymous, please try the benchmark yourself with conservative and ondemand. conservative is too slow on the switches, you will loose performance and battery power.

  17. Actually, the sudo command didn’t work because by default you cannont overwrite a file with sudo.

    And Chris, “sudo -i” … that’s not a regular option for sudo on many versions (it’s new as of 1.6.8p[something])

    I should know, I’ve been using sudo for over 11 years and was the main port verifer for Irix 6.x and ReliantUNIX

  18. brian, “sudo -i” is a standard option for Ubuntu Dapper, the distro the HowTo was originally written for. I should know because Ubuntu is all I use :)

  19. would we use the speedstep-centrino module for a core duo chipset? would we also add 2 lines, one for each processor

    devices/system/cpu/cpu0/cpufreq/scaling_governor=ondemand
    devices/system/cpu/cpu1/cpufreq/scaling_governor=ondemand

  20. I think ondemand is clearly a governor on cpufreq. However, what about those on Mobile Intel Pentium 4 processors? (i.e., those that don’t run on Centrino).

  21. Pingback: TimmyBLOG » Blog Archive » links for 2006-08-18

  22. Pingback: links for 2006-08-17 » D.C Life

  23. Pingback: Linux - How To Make Firefox Over 40% Faster : Tech Tips

  24. Pingback: Donghai Ma » links for 2006-08-18

  25. Amusingly, a lot of people are trying to do ‘sudo echo ondemand > /sys…’ and saying “oh you can’t write to sys with sudo” because they don’t understand what they are doing.

    When you use shell redirects, the shell outputs STDOUT to the file specified. The shell is not a root shell; that’s why you’re using sudo in the first place. In essence, echo is run as root, and then $(id -n -u) attempts to write the output.

    The comment to pipe to ‘sudo tee’ was good; tee will wind up writing to the file, and will be run as root.

  26. Pingback: wimac | project » links for 2006-08-19

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>