Firefox/Profile on RAM
Assuming that there is memory to spare, placing Firefox's cache or complete profile to RAM offers significant advantages. Even though opting for the partial route is an improvement by itself, the latter can make Firefox even more responsive compared to its stock configuration. Benefits include, among others:
- reduced drive read/writes;
- heightened responsive feel;
- many operations within Firefox, such as quick search and history queries, are nearly instantaneous.
To do so we can make use of a tmpfs.
Because data placed therein cannot survive a shutdown, a script responsible for syncing back to drive prior to system shutdown is necessary if persistence is desired (which is likely in the case of profile relocation). On the other hand, only relocating the cache is a quick, less inclusive solution that will slightly speed up user experience while emptying Firefox cache on every reboot.
Relocate cache only to RAM
When a page is loaded, it can be cached so it doesn't need to be downloaded to be redisplayed. For e-mail and news, messages and attachments are cached as well. Firefox can be configured to use only RAM as cache storage. Configuration files, bookmarks, extensions etc. will be written to drive as usual. For this:
about:configin the address bar
browser.cache.disk.enableto "false" (double click the line)
- verify that
browser.cache.memory.enableis set to "true" (default value)
- add the entry (right click->new->integer)
browser.cache.memory.capacityand set it to the amount of KB you'd like to spare, or to -1 for automatic cache size selection. (Skipping this step has the same effect as setting the value to -1.)
Main disadvantages of this method are that the content of currently browsed webpages is lost if browser crashes or after a reboot, and that the settings need to be configured for each user individually.
A workaround for the first drawback is to use anything-sync-daemon or similar periodically-syncing script so that cache gets copied over to the drive on a regular basis.
Place profile in RAM using tools
Use an active management script for maximal reliability and ease of use. Several are available from the AUR.
- Profile-sync-daemon wiki article for additional info on it; AUR - refer to the
Place profile in RAM manually
Before you start
Before potentially compromising Firefox's profile, be sure to make a backup for quick restoration. Replace
xyz.default as appropriate and use
tar to make a backup:
$ tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/xyz.default
Adapted from verot.net's Speed up Firefox with tmpfs
The script will first move Firefox's profile to a new static location, make a sub-directory in
/dev/shm, softlink to it and later populate it with the contents of the profile. As before, replace the bold sections to suit. The only value that absolutely needs to be altered is, again,
Be sure that rsync is installed and save the script to
~/bin/firefox-sync, for example:
#!/bin/sh static=main link=xyz.default volatile=/dev/shm/firefox-$USER IFS= set -efu cd ~/.mozilla/firefox if [ ! -r $volatile ]; then mkdir -m0700 $volatile fi if [ "$(readlink $link)" != "$volatile" ]; then mv $link $static ln -s $volatile $link fi if [ -e $link/.unpacked ]; then rsync -av --delete --exclude .unpacked ./$link/ ./$static/ else rsync -av ./$static/ ./$link/ touch $link/.unpacked fi
Close Firefox, make the script executable and test it:
$ killall firefox firefox-bin $ chmod +x ~/bin/firefox-sync $ ~/bin/firefox-sync
Run Firefox again to gauge the results. The second time the script runs, it will then preserve the RAM profile by copying it back to disk.
Seeing that forgetting to sync the profile can lead to disastrous results, automating the process seems like a logical course of action.
Manipulate the user's cron table using
$ crontab -e
Add a line to start the script every 30 minutes,
*/30 * * * * ~/bin/firefox-sync
or add the following to do so every 2 hours:
0 */2 * * * ~/bin/firefox-sync
Sync at login/logout
Assuming bash is being used, add the script to the login/logout files:
$ echo '~/bin/firefox-sync' | tee -a ~/.bash_logout ~/.bash_login >/dev/null