Pages

Friday, May 28, 2010

Powersaving Bughunting

I spent most of yesterday working on Bug 567339, which is about removing unnecessary CPU wakeups in order to save power (which is very important on mobile devices - the fewer time the CPU is woken up from sleep, the longer your battery will last, since each wakeup disturbs sleep mode for a short while after the actual activity).

So, long story short, it seem the bug is that timers for image animations are not canceled. In other words, if you view an image with animations, then a timer is created for each image, and it does the rendering at the proper rate, but the timer keeps running after the image is no longer needed. So you keep getting CPU wakeups at the appropriate rate for the animations, wasting power.

(This is actually an issue on normal Firefox as well, not just mobile - some CPU cycles are being spent on these timers. It is probably negligible, though, but still wasteful.)

The longer story of hunting the cause of the bug is as follows:
  • A helpful person reports the bug, and mentions a suspicion of https being the cause (since enabling/disabling https affects the symptoms). At issue here are 4 wakeups/second which should not be happening.
  • Trying to reproduce the bug, it turns out that it happens in nightly builds, but not when building from source in trunk. Hmm.
  • Trying to figure out the difference, one noticeable change between the nightly builds and building from source is that the start page shows some suggestions of addons in the nightly, but building from source does not. Turns out this is because /trunk reports itself as 2.0, and no addons exist for that yet. Changing the reported version to 1.1 leads to addons being suggested, and the bug in fact occurs.
  • Since fetching addon suggestions is done from AMO through https, and the original bug report strongly suspected https as the culprit, it would seem we are almost done here. Or are we?
  • Actually inspecting all the wakeups (this was where most of the time I spend on this bug was; I put up a wiki page with some details of the methodology I used) eventually reveals that the vast majority of wakeups are in fact of imgContainer::notify()... and not https or anything network related.
  • To confirm this, removing the animated image that was shown when loading addon suggestions removes the wakeups... and indeed, the image had 4 frames/second, exactly the number of wakeups we were hunting!
Still working on figuring out why this happens and how it can be resolved.

    Monday, May 24, 2010

    How to copy files to an N900

    Today was my first interaction with an N900, and it was not smooth at all. After several hours of messing around, it seems the 'proper' way to copy files from your desktop to the N900 is:
    • Connect N900 via USB, in 'mass storage' mode
    • Open the mounted drive in your desktop, and copy files
    • Unmount the drive
    • Disconnect the USB cable
    • If you have a terminal open in the N900, close it
    • Open a terminal in the N900 and go to ~/MyDocs. The files you transferred will be there.
    Thanks go out to the people that helped me on IRC.

    Wednesday, May 19, 2010

    Electrolify()?

    I proposed an idea for e10s-enabling existing code - that is, making existing code work with the new electrolysis framework in Firefox, which splits things into separate processes. A bug to track the issue is here, and it includes a working patch I wrote (well, working just well enough to show the kind of JavaScript code this approach would allow).

    Friday, May 7, 2010

    Lesson #1: Improper XPCOM definitions can lead to silent failure

    I've been tasked with implementing electrolysis (e10s) support for FTP. That means letting child processes (content) send requests to the parent process (chrome), which actually does the networking - while from the perspective of the child process, the interface to an FTP channel is the same.

    As this is just my second week at Mozilla, I am still learning the build process, fundamental technologies like XPCOM, and other stuff about the codebase. So I ran into some problems, which I'll mention here on the blog in hopes that they help other people that search for the same keywords.

    So, lesson #1 is: Improper XPCOM definitions can lead to silent failure.

    Specifically, the issue was that this:

      NS_IMPL_ADDREF_INHERITED(FTPChannelChild, FTPBaseChannel)
      NS_IMPL_RELEASE_INHERITED(FTPChannelChild, FTPBaseChannel)

      NS_INTERFACE_MAP_BEGIN(FTPChannelChild)
        NS_INTERFACE_MAP_ENTRY(nsIRequest)
        NS_INTERFACE_MAP_ENTRY(nsIChannel) 
        NS_INTERFACE_MAP_ENTRY(nsIFTPChannel)
      NS_INTERFACE_MAP_END_INHERITING(FTPBaseChannel)

    was needed, and I was missing the nsIRequest line. I missed it because nsIRequest is a parent interface, and I didn't realize it was also necessary. And, indeed, when sent through JavaScript to a function that expects to receive an object with that interface, it fails. What was tricky was it silently failed - I called a JavaScript function, which was known to work, and it simply returned a failure code, without even starting the function. Only by stepping through all the JS embedding code did it eventually become clear to me that a call to QueryInterface was failing, so the JS embedding code was failing to set up the parameters for the JS function, and not even calling it.