Friday, March 1, 2013

Web browsers and laptop battery

My Thinkpad X220 comes with a whopping 9-cell 93Wh battery, it is supposedly to go for more than 10 hours but I had been getting only about 7. I had to start an investigation to find out what were using so much more power. One of them is web browser, mainly due to too high timer resolution.

According to Microsoft: if the timer resolution is increased, processor power management technologies may not be effective and can cause up to 25% more power consumption. Who increases TR?

Flash, surprise? the thing I hated, very much, since the very first day of its appearance.

When a browser is playing a flash content such as Youtube, TR is locked to 1 ms. After playing, Flash releases the TR lock, but some browsers, FireFox and Chrome, do not set the TR back to 15.6 ms until you close entirely these browsers. There is no cure for Chrome, but you can easily patch FF 4 and 5.

Open the xul.dll (found in FF installation folder, usually C:\Program File (x86)\Mozilla Firefox) in a hex editor such as Hex Workshop, search for 0x538A5C240C568B74240C3A5E2C741784DB6A01, and change the last byte from 01 to 10.

Obviously I can no longer use Chrome and now I use Opera 12 instead.

Of course, nobody should allow a browser to play flash automatically. For Opera, simply check "Enable plug-ins only on demand". For FF 4 and 5, rename the userContent-example.css file to userContent.css and add the following lines:

object[classid$=":D27CDB6E-AE6D-11cf-96B8-444553540000"],
object[codebase*="swflash.cab"],
object[type="application/x-shockwave-flash"],
embed[type="application/x-shockwave-flash"],
embed[src$=".swf"]
{ -moz-binding: url("http://www.floppymoose.com/clickToView.xml#ctv"); }


BTW, you may also want to add the following lines to prevent scrolling marquee and blinking text:

marquee { overflow:visible; display:block; height:auto ! important; }

blink { text-decoration: none ! important; }


Like flash, they are both battery and eye unfriendly. Don't worry, you can still see the text, just no more scrolling and blinking. For Opera, you create a new file named as user.css, add these two lines and put it in the style folder under the Opera installation folder, usually C:\Program Files (x86)\Opera\styles.

Another thing that had been draining too much battery was the webcam. Once my X220 has been waken up from a sleep, this thing prevents the USB port from suspending. I disabled it in BIOS, because I never use it.

Note that browsers are not the only ones that change and lock TR to 1ms; so you should always close the programs that you do not use to save energy. In my case they are CyberLink PowerDirector 10 and DxO Optics Pro 8.

So, how do I know which hardware and software are using too much energy? Simple, just open a CMD Prompt and run "powercfg -energy" and don't touch your laptop. After 1 minute, open the energy-report.html and you'll see your problems.


One more little tip for Opera: open opera:config, search for chrome, change "Chrome Integration Drag Area" from 20 to 0. This will move the tabs up to the title bar like Google Chrome:


Now my X220 goes for 10 to 12 hours on WiFi browsing. Above findings and cures apply to any other laptops.

Abstract in Chinese

系统定时器的精度一般是15.6毫秒,但是一些浏览器比如FireFox和Chrome一旦打开Flash后,会把定时器的精度锁到1毫秒,导致多达25%的额外耗电,直到你把这些浏览器彻底关掉之后才会恢复。FF的补丁很简单,把xul.dll的一个字节改一下即可。Chrome目前没有解决办法,只能改用别的浏览器比如Opera。使用Opera之后,包括阻挡Flash、滚动和闪烁文字,另外在BIOS里关掉摄像头,我的Thinkpad X220的WiFi浏览时间由原来的7小时左右大大延长到10至12小时。

5 comments:

  1. tried to set FF19 but couldn't locate the strings in the xul.dll file. any help?

    ReplyDelete
    Replies
    1. Try search for the last 8 or so digits.

      Maybe it is already fixed in the newer versions? You can use two utilities to check Timer Resolution instantly without having to wait for 1 min with powercfg. ClockRes.exe is a DOS command; TimerResolution.exe is a GUI and can set TR too.

      Delete
    2. yes it seems that it's fixed in firefox. after I close the youtube, it goes back to 15.6ms. even when the video is played, it's more than 1ms.

      Delete
  2. Increasing battery life is far more important on laptops and tablets

    ReplyDelete
  3. Always let your battery run out at least once a month, keeps the battery's life longer.

    ReplyDelete