Saturday, February 27, 2010

Sluggish Firefox Browser in Linux

Discussions suggest that a lot of Firefox's sluggishness on Linux (as compared to Windows) is due to Intel compiler profiling (maybe, but GCC offers profiling), compiler cpu optimizations (i386 vs. i686 -- not so much anymore; Mandriva compiles Firefox for i586 - see BONUS at the end) and Linux's use of pango, a library for laying out and rendering text with an emphasis on internationalization (likely a cause of slowness).

Let's get rid of Pango support first. This is easily done by editing your .bashrc file and adding at the end
 export MOZ_DISABLE_PANGO=1

 Resource your .bashrc with

$ source .bashrc

You could also put the line of export code in .bash_profile. Then just re-start Firefox to get the benefit.

Short of recompiling Firefox (which appears to be a daunting task), we have found something that helps if you have RAM available. The trick is to keep the disk cache in /dev/shm, a POSIX-compliant temporary filesystem (tmpfs).

Let's use /dev/shm to help the entire system as well, so modify /etc/fstab as follows (see above link for what the defaults values actually are):
/dev/shm /tmp tmpfs defaults,mode=1777 0 0

Now, using about:config in Firefox, set the value of browser.cache.disk.parent_directory
to /tmp. Firefox will automatically create a /Cache directory there when it runs. You can see it working with df -h.

BTW, Firefox will not use tmpfs when you are in Private Browsing. Then, Firefox disables the disk cache, clears the memory cache and uses memory cache only.

Using /dev/shm on /tmp may also offer advantages to systems with multiple CPUs.

Other Possibilities
I've also seen a script that moves all of ~/.mozilla to tmpfs and
back, but have not yet experimented with it. That claims to be faster since all the javascript scripts and sql database files are in RAM.

There's some talk of win32 Firefox on WINE being faster than native Linux.

You can also mount ~/tmp the same way with:
/dev/shm /home/USER/tmp tmpfs defaults,mode=40700 0 0

BONUS
If you want to know how your build of Firefox was done, check its build configuration with about:buildconfig.

No comments: