Speed Up Firefox (Linux Only)

By | January 6, 2009


Here is another tip for Linux users only by Andrei.

Speed up Firefox by mounting the profile in tmpfs

tmpfs is a virtual, RAM-backed filesystem. It’s lightning-fast, but since it’s RAM-backed, any file written to tmpfs uses precious memory while it’s there, and the entire contents of the virtual partition are lost on shutdown or crash. The good news is that these detriments can be minimized, making tmpfs a viable choice for your profile directory. This document gives some tips on how to mount your Firefox profile in a tmpfs partition while minimizing the downsides of tmpfs.


Step 1. Reduce the size of your profile directory.

tmpfs is RAM-backed, so we want to conserve memory by trimming the fat from the profile. I recommend making the following config changes (enter ‘about:config’ in the Firefox address bar):

set browser.cache.disk.capacity to 20000 or thereabouts
set browser.safebrowsing.enabled to false
set browser.safebrowsing.malware.enabled to false

The first one reduces the size of the disk cache to about 20 MB, down from 50MB. It might be tempting to turn disk cache off entirely, but I’ve encountered poor performance doing that in the past; I think that the caching algorithm has to be able to push things into disk cache for best performance, even if they won’t stay there long.

The last two disable the collection of the information in the ‘urlclassifier*.sqlite’ files. These hold Firefox’s database of suspected malware or phishing sites, and while most users will feel comfortable turning this off, it does in theory leave you more vulnerable to these types of attacks. There’s a known bug in Firefox which can make these files grow quickly; on my system, they were 70MB total.

After you’ve changed these settings, clear the cache in Firefox and delete the urlclassifier*.sqlite files from your profile directory. (SQLite will recreate empty databases but they’ll stay at 32k.)

Step 2. Edit the fstab and prepare the backup tarball.

First, create a tarball of your profile as it currently stands.
Code:
$ cd
$ cd .mozilla/firefox
$ tar cpf packed.tar abcd1234.default

abcd1234.default should be replaced by your profile directory name here and below.

Now edit /etc/fstab and add a line like this:
Code:
firefox /home/steven/.mozilla/firefox/abcd1234.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=100 0 0

You’ll have to adjust path components, uid and gid.

Step 3. Set up a backup and restore script.

This is an example, but is by no means the only way to do it. I’ll assume you’ve named the script “${HOME}/.pack_ffox.sh” in future commands, so replace that with whatever you decide to do.
Code:
#!/bin/bash# Change this to match your correct profile
PROFILE=”abcd1234.default”

cd “${HOME}/.mozilla/firefox”

if test -z “$(mount | grep -F “${HOME}/.mozilla/firefox/${PROFILE}” )”
then
mount “${HOME}/.mozilla/firefox/${PROFILE}”
fi

if test -f “${PROFILE}/.unpacked”
then
tar –exclude ‘.unpacked’ -cpf packed.tmp.tar “$PROFILE”
mv packed.tar packed.tar.old
mv packed.tmp.tar packed.tar
else
tar xpf packed.tar &&\
touch “${PROFILE}/.unpacked”
fi

This script will load your firefox profile if it hasn’t been loaded, and save it otherwise (keeping one backup copy from a few minutes ago in case of file corruption or the like). Once you’ve got it saved, you’ll need to quit Firefox for this next step. Open in links, copy and paste to a text editor, or just remember the steps.

Step 4. Switch over.

With Firefox closed, you need to empty your profile directory. Either move the files currently in there to a new folder, or simply erase them (remember, a copy is in packed.tar as well). Be sure to leave the empty profile directory there for the tmpfs mount point.

Now, run the script:Code:
$ “${HOME}/.pack_ffox.sh”

Verify that your profile directory is now mounted on tmpfs, that your files got correctly unpacked, and that the file .unpacked exists inside of your profile directory.

Now run the script again, exactly as before. This time, it will detect that your profile’s been unpacked and is ready to use, and create a new packed.tar. If it worked, you should now have the file “.mozilla/firefox/packed.old.tar” as well.

If both of those things checked out, you’re clear to start Firefox again.

I recommend adding the command to your .xinitrc or desktop-environment-specific startup settings, so that it’s ready to go when you log in. It’s also critical that you run it again before you shut down your computer, or you’ll lose all changes. One of the safest ways for users on media that doesn’t have limited write-cycles is to simply add an entry to the crontab which runs the script every five minutes. Run this command to edit the crontab:
Code:
# crontab -u USERNAME -e

which will bring up your editor. Add a line akin to this one:
Code:
*/5 * * * * $HOME/.pack_ffox.sh

Check in five minutes to make sure the mtime of packed.tar has changed, indicating that the script is working [just right click the tarball and look when it was last modified].

Notes:

I use Ubuntu, and for me some of the steps above had to be changed a little. For example, my FF profile was much bigger because of the many extensions i have installed, so i change the partition size to 200, so you can change the size to your needs as well.

To set up the crontab in Ubuntu, i just wrote: “crontab -e” in a terminal and added the line “*/5 * * * * $HOME/.pack_ffox.sh” [without the quotes]

[digg-reddit-me]


About (Author Profile)


Vygantas is a former web designer whose projects are used by companies such as AMD, NVIDIA and departed Westood Studios. Being passionate about software, Vygantas began his journalism career back in 2007 when he founded FavBrowser.com. Having said that, he is also an adrenaline junkie who enjoys good books, fitness activities and Forex trading.

Comments are closed.