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 Responses to “How To Make Firefox Over 40% Faster”

  1. Eli’s Daily Articles » Blog Archive » How To Make Firefox Over 40% Faster on August 16th, 2006 10:16 pm

    [...] read more | digg story [...]

  2. Anonymous on August 17th, 2006 8:46 am

    This has _nothing_ to do with FIREFOX!!!

    Go fishing, please.

  3. martinus on August 17th, 2006 9:00 am

    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.

  4. The Independant Penguin » Blog Archive » How To Make Firefox Over 40% Faster on August 17th, 2006 11:42 am

    [...] Full Story Explore posts in the same categories: GNU/Linux News [...]

  5. Bob on August 17th, 2006 11:43 am

    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.

  6. Pierre on August 17th, 2006 11:43 am

    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’

  7. jan on August 17th, 2006 12:00 pm

    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.

  8. ketsugi on August 17th, 2006 12:19 pm

    ketsugi@Asahara:~$ sudo su -c

  9. rbnet on August 17th, 2006 12:43 pm

    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.

  10. mac on August 17th, 2006 12:54 pm

    permission denied….

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

  11. John Flinchbaugh on August 17th, 2006 1:33 pm

    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.

  12. Dinges’ Blog » Blog Archive » La Cienega Just Smiled on August 17th, 2006 2:14 pm

    [...] I wish the little town I set up a super fast network! Should you stop using Google? How to make Firefox work smoking fast! [...]

  13. Anonymous on August 17th, 2006 2:23 pm

    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?

  14. Anonymous on August 17th, 2006 2:33 pm

    What speedstep module do I use for Dapper on a VM? the real processor is a P4.

  15. Anonymous on August 17th, 2006 2:57 pm

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

  16. theine on August 17th, 2006 3:15 pm

    You can

  17. Austoon Daily » How To Make Firefox Over 40% Faster on August 17th, 2006 3:40 pm

    [...] How To Make Firefox Over 40% Faster [...]

  18. knobbt on August 17th, 2006 4:23 pm

    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).

  19. RMX on August 17th, 2006 4:49 pm

    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.

  20. martinus on August 17th, 2006 4:52 pm

    thanks for pointing out that sudo echo does not work, I have fixed this in the article.

  21. Psy-Q on August 17th, 2006 6:24 pm

    The powersave governor is called powersave, not powersafe. It doesn’t do anything to make your power any safer.

  22. Chris on August 17th, 2006 6:39 pm

    Just replace su with sudo -i and it’ll work when modifying /sys I’m surprised no one else mentioned this :P

  23. Anonymous on August 17th, 2006 6:47 pm

    This article is complete bollocks.

    But try the ‘conservative’ governor, it works better.

  24. martinus on August 17th, 2006 6:59 pm

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

  25. brian on August 17th, 2006 7:22 pm

    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

  26. Andy on August 17th, 2006 7:41 pm

    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 :)

  27. Anonymous on August 17th, 2006 7:47 pm

    do sudo -s -H to get root access and try again

  28. discord on August 17th, 2006 10:02 pm

    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

  29. Keith on August 17th, 2006 11:13 pm

    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).

  30. TimmyBLOG » Blog Archive » links for 2006-08-18 on August 18th, 2006 2:35 am

    [...] How To Make Firefox Over 40% Faster < Programming Kung Fu (tags: del.icio.us firefox HowTo links linux reference ubuntu web tutorial tips laptop) [...]

  31. links for 2006-08-17 » D.C Life on August 18th, 2006 3:01 am

    [...] How To Make Firefox Over 40% Faster < Programming Kung Fu (tags: firefox) No Tags .adHeadline {font: bold 10pt Arial; text-decoration: underline; color: blue;} .adText {font: normal 10pt Arial; text-decoration: none; color: black;} [...]

  32. Linux - How To Make Firefox Over 40% Faster : Tech Tips on August 18th, 2006 3:52 am

    [...] 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. [...]

  33. Anonymous on August 18th, 2006 5:53 am

    Talk about a misleading title. Get the facts:

    http://www.FirefoxMyths.com

  34. Anonymous on August 18th, 2006 6:13 am

    Darn it! You should have mentioned “power management” or some such phrase in your title.

  35. Donghai Ma » links for 2006-08-18 on August 18th, 2006 6:34 am

    [...] How To Make Firefox Over 40% Faster (tags: computer linux performance tips tutorial reference) [...]

  36. John on August 18th, 2006 8:46 pm

    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.

  37. wimac | project » links for 2006-08-19 on August 19th, 2006 2:20 am

    [...] How To Make Firefox Over 40% Faster sudo apt-get remove powernowd (tags: ubuntu linux firefox browser) [...]

  38. lozzman on December 1st, 2008 5:30 pm

    hey,

    i want to know how i can make firefox.exe to high prioroty PERMANENTLY! using a shortcut or the registry, i have mozilla 3.0 ( dont ask why ) and vista home premium!

    email me lozzman@hotmail.co.uk

  39. Martin Ankerl on December 2nd, 2008 2:31 pm

    Hi lozzman! This is very simple in Linux, although I would not recommend it. Glad I could help! :-)

Leave a Reply