Categories
Firefox Memory consumption MemShrink

Another leak fixed

Bug 654106 was just fixed by Henri Sivonen.  The leak was somewhere, in the HTML5 parser;  a small amount of memory would leak any time .innerHTML was set on an element.  Thanks to Henri for fixing it, to Hughmann for filing a wonderfully precise and easy-to-reproduce bug report, and to Boris Zbarsky and Mike Hommey for helping with the diagnosis.

With that bug fixed, that leaves 34 unresolved bugs hanging off bug 640452, the tracking bug for memory leaks.

Categories
about:memory Firefox Massif Memory consumption

A better about:memory: stage 1

A while ago I wrote about some ideas I had for improving about:memoryBug 653633 has been tracking the first stage of this (and it now also has a feature page) and it only needs to pass super-review to be ready for landing.

Here’s what the old about:memory looks like.

Old about:memory output

Some things to note:

  • The “Memory mapped” and “Memory in use” numbers are for the heap, not the entire process.
  • The “Memory mapped” and “malloc/mapped” numbers are the same, as are the “Memory in use” and “malloc/allocated” numbers (modulo tiny differences due to memory allocations that occur while generating the page).
  • It’s a big list without much information how the different entries relate.  If you hover over the names you get a tool-tip that explains a bit more, but it’s often not much of a help.
  • Something not obvious from the above screenshot is that if you cut and paste the output into a text box it looks horrible.  Eg. see this Bugzilla comment.  This makes it hard to use in Bugzilla reports.

Here’s what the new about:memory looks like:

New about:memory output

Things to note:

  • Most of the output use a tree-based representation which shows the hierarchy of the memory breakdown.  I.e. overall use is broken into multiple chunks, and each of those chunks are broken into sub-chunks, and so on.  This makes it much easier to see where the bulk of the memory usage is occurring.
  • The use of percentages helps with this too.
  • Sizes are reported in MB, not bytes.  (I wanted to use “MiB” instead of “MB”, but was discouraged by the prior holy war about this issue that bug 106618 documents!)
  • The “Mapped Memory” tree gives the high-level overview.  The root of that tree is the total memory used by the process (which the old about:memory did not list).
  • The “Used Heap Memory” tree gives the breakdown for the used part of the heap (which corresponds to the “mapped/heap/used” figure in the “Mapped Memory” tree).  I show the used heap separately because most of the time that’s the most interesting information.  In contrast, the “Mapped Memory” tree is often dominated by code and data segments, which don’t correspond to explicit memory allocation requests from the process and so are less variable and harder to improve.
  • “Other Measurements” holds measurements that overlap with the tree breakdown.  The new “resident” figure tells you how much physical memory is being used by the process.
  • Entries that cover a very small section of memory (less than 0.1% of the used heap, for the “Used Heap Memory” tree) are aggregated into entries that look like “(2 omitted)”.  This means that more memory reporters can be added in the future without the output being cluttered up by tiny entries.
  • If you click on the “More verbose” link at the bottom, the page redraws showing all the sizes as bytes instead of MB, and aggregated entries are shown in full.
  • It handles multiple processes.  If you view about:memory in Fennec you get output for each process separately.  The plug-in container process isn’t represented at the moment, though;  bug 648415 is open for adding that, though it’s of less interest since plug-ins like Flash are out of Mozilla’s control.
  • You can’t see it in the picture, but the tool-tips describing each metric are clearer, more consistently expressed, and expressed as complete sentences.
  • The formatting is much more similar to other “about:” pages such as about:cache and about:buildconfig.
  • You can cut and paste the output into a text box and it reproduces beautifully.  The lines used to represent the tree structure are Unicode box-drawing characters, and I stuck to the subset that are most commonly supported by terminals.  The generated HTML has newlines in just the right places so that whitespace is inserted nicely.  Here’s an example:
Main Process

Mapped Memory
634.89 MB (100.0%) -- mapped
├──526.33 MB (82.90%) -- other
├──106.00 MB (16.70%) -- heap
│  ├───53.34 MB (08.40%) -- used
│  └───52.66 MB (08.29%) -- unused
└────2.56 MB (00.40%) -- js
     ├──2.44 MB (00.38%) -- mjit-code
     └──0.13 MB (00.02%) -- tjit-code

Used Heap Memory
53.34 MB (100.0%) -- heap-used
├──22.22 MB (41.65%) -- js
│  ├──21.00 MB (39.37%) -- gc-heap
│  ├───0.75 MB (01.41%) -- tjit-data
│  │   └──0.75 MB (01.41%) -- allocators
│  │      ├──0.56 MB (01.06%) -- reserve
│  │      └──0.19 MB (00.35%) -- main
│  ├───0.35 MB (00.66%) -- mjit-data
│  └───0.11 MB (00.21%) -- string-data

The screenshots above are from my Ubuntu Linux box.  Funnily enough, on Mac the lines in the box-drawing characters don’t line up consistently so the output doesn’t look as nice, as this screenshot shows:

New about:memory output on Mac, showing misaligned box characters

Not much that can be done about that, as far as I know;  it’s certainly not a show-stopper.

My hope is that this revamped about:memory will be the first place both users and developers look when trying to understand any issue related to memory usage.  For example, it should subsume OS memory reporters like ‘top’, ‘ps’ and the Windows task manager.  This will make bug reports easier to understand;  in particular it will help avoid the problem where someone says “Firefox is using 800MB of memory” and you don’t know which metric they are using.

There are some definite improvements to be made.  Most notably, the “heap-used/other” entry is usually the largest one in the “Heap Memory Used” tree — large chunks of memory aren’t being covered by memory reporters, so new ones need to be added.  Working out what these reporters are won’t be easy, but Massif should be a big help.

After that, it’d be great to have reporting at the level of individual tabs or something like that.  Mike Shaver has a draft patch adding an about:compartments page which reports about JavaScript memory usage for individual compartments, which correspond to domains.  This is a great start, though I’d like non-JavaScript memory usage to also be divided in this way.  The details of how best to do this are not yet clear to me.

The new about:memory is on track to make it into Firefox 6.  Hopefully it will help reduce Firefox’s memory consumption.

Categories
Firefox Memory consumption

Some big memory leaks in the add-on SDK are getting fixed

I know almost nothing about the add-on SDK, so please see bug 607601 for details.  Bug 642306, bug 646575 and bug 649334 are similar and hopefully will also be fixed soon too.  Great work by Alexandre Poirot!

(And if anyone who does know about the add-on SDK can explain a bit more about these leaks and which add-ons are affected, I’d love you to do so in the comments.  Thanks!)

Categories
Firefox Software Engineering Talks

A talk: Software Engineering for Firefox

I’m giving a talk at Monash University on Thursday, to students in a 2nd year software engineering class and anyone else who wants to come along, about Firefox development.

Here is a draft version of the slides.

Draft slides

(I wanted to embed a Scribd widget but I can’t get it to work.) I used PowerPoint to make them but I’ve assiduously avoided the common (and widely pilloried) PowerPoint style — there isn’t a single bullet point. Each slide also contains the presenter notes, which indicates more or less what I’m going to say, but don’t worry, I won’t be reading them verbatim. I’ve included those notes because if you read the slides without them you’ll miss a lot of the details.

I’d appreciate any feedback that people might have about these slides.  Thanks.

Categories
Tinderbox

Warnings-as-errors in js/src/, take 2

I recently wrote that we changed the way the JavaScript shell was built so that it would treat compiler warnings as errors.  Unfortunately, we had to back it out.  It was working fine on common configurations, particularly those that are part of our standard tinderbox testing, but it was causing too much breakage for people using unusual configurations.

Then Paul Biggar suggested a lovely compromise of adding a special build to the standard tinderbox testing of TraceMonkey.  That way, we’d know about compiler warnings on the most important platforms.  Phil Ringnalda went and implemented the idea with some help from Chris Atlee, and now we have a warnings-as-errors build (under “SM (e)”):

SM (e) build on TBPL

Amazing enough, it was green on its first run.

Thanks guys!  This build is currently only showing up on Phil’s development version of TBPL, it’ll make it onto the official TBPL sometime soon.

And now I wonder if something similar could be done for whole-browser builds…

Categories
Fennec

You can build and run Fennec on a desktop machine

Yesterday I learned that you can build and run Fennec on a desktop machine:

Fennec running on a Linux desktop

The build instructions are pretty straightforward, just ignore all the stuff about Maemo and Scratchbox, you don’t need them for desktop builds.  Everyone else probably already knows you can do this, but I’m writing this just in case some others don’t.

I’m a smartphone Luddite, so this is the first time I’ve actually tried Fennec myself.  It’s pretty cool!  Though I haven’t worked out how to quit yet.  Well, I can do it on the desktop by closing the window, but that’s not within Fennec itself and so presumably isn’t possible on a smartphone.

Categories
Firefox Personal

Mum ♥ glow.mozilla.org

My mother has been staying with me and my family this past week. I told her about the Firefox 4 release, and showed her glow.mozilla.org.

Firefox 4 download counter

She was mesmerized:  “There’s one in Japan… oh, one in Sydney… South America’s doing well… several in Russia…”  I’ve pulled my laptop out to show her it several times, and given her download counts multiple times a day: “7.1 million in the first day… 10 million… 22 million… 35.5 million…”  As a result, I’ve gone on to explain to her a lot more about Firefox, its history, competition between browsers, and how I contribute to Firefox.

I give a big thank you and congratulations to the metrics team for presenting some potentially dry statistics in a beautiful, compelling and easy-to-understand manner!

Categories
Uncategorized

Warnings-as-errors in js/src/

Bug 609532 changed the way the JavaScript shell is built so that compile warnings are treated as errors.  We already had a zero-tolerance policy for compile warnings in js/src/, but they tend to creep in, especially on Windows, because most people develop on Mac or Linux.  Already at least one Windows build turned red because of a warning, and it was immediately fixed by the dev responsible. Previously that warning would have lasted for days or weeks until someone on Windows got sick enough of it to fix it.

I’d love to see the same thing done for the entire browser, but judging by the reams of compile warnings that go by when building the browser, this won’t happen any time soon.

Oh, and if you don’t know about make -s (a.k.a. make --silent or make --quiet), you should try it. It’s indispensible!

Categories
JägerMonkey Memory consumption

The JavaScript interpreter isn’t dead yet

During most of the development of JaegerMonkey, the JavaScript engine was configured so that JaegerMonkey compiled all executed JavaScript code.  Which meant that the old JavaScript interpreter was unused (with the exception that it’s still used during the recording phase during trace compilation).

However, we eventually discovered that lots of JavaScript functions are only run a small number of times.  Compiling such functions is a bad idea — compilation is slow, and the generated code can be quite large.  Bug 631951 changed things so that a function is only compiled once it has run 16 times, or any loop within it has run 16 times.

This didn’t end up making much speed difference, but it reduced the amount of code generated by JaegerMonkey by a lot;  I saw numbers ranging from 2.5x to 6.5x on different workloads.  For techcrunch.com, which is JS-intensive, this translates into roughly a 30MB saving on a 64-bit machine.

And the interpreter lives another day.

Categories
Uncategorized

Community Service Announcement

Prepending ‘@’ to somebody’s name does something useful in Twitter.  Outside of Twitter, it’s extra typing and looks silly.