Comzeradd posted a great article recently on how to speed up firefox by moving your ~/.mozilla folder on a tmpfs mount.
As you probably know, firefox keeps track of everything you visit while you browse the web infinity, then allows you to quick-search that history just by typing in its awesome bar –err, address bar
Unfortunately, after a while the whole thing slows down and gets a bit annoying. So what Comzeradd tried was to move ~/.mozilla (which includes the history database) on a tmpfs mount.
The difference is staggering! Searches are snappy again and even firefox itself feels faster!
Comzeradd offers a script that syncs your tmpfs ~/.mozilla with a folder on your hdd to make sure you won’t lose your data on reboot/shutdown/powerfail.
I took this a step further by creating a firefox wrapper script. After you move your ~/.mozilla folder to a safe place, this script makes sure that your data is always synced between the tmpfs folder and your hdd folder on a fixed interval.
what the script does, in steps:
- check that we don’t have any stale ~/.mozilla folder
- rsync our hdd copy of .mozilla with our tmpfs
- launch a background process that syncs any changes on the tmpfs .mozilla folder back to our hdd copy every one minute (adjustable)
- launch firefox
- when firefox ends, kill background process and sync back to the hdd one last time
To use the script, you’ll first need to mount tmpfs to a folder. On my laptop I have my /var/tmp as tmpfs (useful for gentoo emerges too). To make /var/tmp a tmpfs folder, you need to edit your /etc/fstab file and add the following line:
tmpfs           /var/tmp   tmpfs size=768M,mode=0777        0 0
You should adjust the size= option based on the ram you have available.
Then just mount the “partition” with:
mount /var/tmp
and execute the script
chmod +x speedfox
speedfox
Thats it! This simple process gives firefox a real boost!
If you start speedfox from a terminal, you can see the rsync info at the beginning and after each minute =]
You can get the script here.
Don’t forget to edit it, read the instructions and configure its variables!
I just installed a similar ‘hack’ on my laptop to use an mfs(4) filesystem for ~keramida/.mozilla and periodically run rdiff-backup to keep copies of this to ~keramida/cache/mozilla.
One of the things I would like to note about using a memory filesystem for ~/.mozilla is that one should be careful to avoid one gotcha:
If the memory filesystem is not mounted, running rsync from ~/.mozilla to ~/cache/mozilla may *delete* all files from the ‘persistent cache’. In my version of the cron job I used (a) a lockfile to avoid having multiple copies of the cron job running at the same time and (b) the following snippet of shell code:
# The runtime mozilla-settings directory.
MOZILLAHOME=”${MOZILLAHOME:-${HOME}/.mozilla}”
# The cache directory for .mozilla application settings.
MOZILLACACHE=”${MOZILLACACHE:-${HOME}/cache/mozilla}”
:
# If the cache directory does not exist, we can’t update it.
if [ ! -d "${MOZILLACACHE}/." ]; then
debug “${MOZILLACACHE} is not mounted.”
exit 0
fi
# If the original .mozilla directory is not an md(4) mount point, we
# haven’t created the memory filesystem for it yet, so skip the update
# to avoid emptying the cache by mistake.
mount | fgrep “${HOME}/.mozilla” > /dev/null 2>&1
if [ $? -ne 0 ]; then
debug “${MOZILLAHOME} is not mounted.”
exit 0
fi
Excellent post & idea. Thanks for sharing it
The lock idea is something I wanted to implement as well but i didn’t get around doing so.
The reverse sync check is also a good idea, although the possibility of my tmpfs unmounting is rather small.
I’ll update the script with those recommendations to make it safer to use.
Thanks for commenting
[...] 还好,有ä½åŒå¦ç»™æˆ‘们写了一份脚本,å‚è§è¿™é‡Œã€‚ [...]
Hello, can this works on Mac?
@Aimin
Maybe, assuming you have rsync and tmpfs support.
@wired
Oh, it’s a pity, I don’t have tmpfs support.
by the way, there is no ~/.mozilla folder on my mac, if I install tmpfs support, could i use this trick to speed up my firefox?
thank you.
[...] 首先æä¾›speedfox.sh脚本一枚[这里,via]~请修改它的å‰å››ä¸ªå˜é‡ä¿å˜å¾…用。 # åŒæ¥åˆ°/dev/shm MOZTMPFS=/dev/shm/mozilla_`whoami`_profile # 原始的ç«ç‹profileç›®å½•å˜æ”¾ç‚¹ï¼Œå¦‚æžœä½ çš„firefoxåªæœ‰ä¸€ä¸ªprofile, # 那么一般是结尾为default的那个目录。我常用的profile是shellex,我的选择是在åŽé¢åŠ .backup MOZHDD="/home/shellex/.mozilla/firefox/yj6mxdhg.shellex.backup" # ç«ç‹å¯åŠ¨æ—¶çš„è¿žæŽ¥ç‚¹ MOZHOME="/home/shellex/.mozilla/firefox/yj6mxdhg.shellex" # åŒæ¥çš„æ—¶é—´é—´éš”,å•ä½ç§’ INTERVAL=600 [...]
Awesome job, thank you for sharing it!
BTW, maybe you know any way to adopt this great idea for Windows (and for Windows Server)?
but I think you may have some thoughts on this as a developer)
(I know this is no the best place to ask,
All the best,
Dave
Great tip, that is awesome. I can’t believe anyone would’t have tmpfs support.. its 2.4 for goodness sake.
Hi,Great article,
I ended up to your post because I was looking for the normal mount option to get the fstab executed: mount -a is the trick btw.
I did also setup the tmpsf for my gentoo tmp folders in make.conf:
PORTAGE_TMPFS=”/mnt/portagetmpfs”
PORTAGE_TMPDIR=”/mnt/portagetmpfs”
BUILD_PREFIX=”/mnt/portagetmpfs”
CCACHE_DIR=”/var/tmp/ccache”
CCACHE_SIZE=”2G”
How about using the inotify option for syncing files to the harddisk?
) csync2
There is also an other tool that syncs quicker, but is more used in clouds if I remember correctly. (…searching…) ah found it (2 days later
[...] http://www.linuxized.com/2009/05/speeding-up-firefox-with-tmpfs-and-automatic-rsync/ [...]
something is really wrong with my tmpfs. see, this is what happens. i forget to use crontab script and somehow firefox restores itself? whats up with that?
Thanks, man. Best article among similar.
[...] ,以及后来的改进:用tmpfs让Firefox在内存中飞驰II ,其中提到的脚本来自speeding up firefox with tmpfs and automatic rsync [...]
[...] 最常见的用途是用内存空间来放Firefox的配置,可以让慢吞吞的FF快很多,参见Shellex的博文:用tmpfs让Firefox在内存中飞驰,以及后来的改进:用tmpfs让Firefox在内存中飞驰II,其中提到的脚本来自speeding up firefox with tmpfs and automatic rsync。 [...]
[...] speeding up firefox with tmpfs and automatic rsync (shell-script) Original [...]