Skip to content

Instantly share code, notes, and snippets.

@SaltwaterC
Created May 15, 2012 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaltwaterC/2699459 to your computer and use it in GitHub Desktop.
Save SaltwaterC/2699459 to your computer and use it in GitHub Desktop.
Browser launchers for RAM drive cache

These are some speed hacks for browsers by moving the cache from the disk to a tmpfs mount point. This hack is not recommended for machines that don't have enough installed memory. These scripts are developed with Ubuntu in mind, therefore they may need adaptation for specific distributions.

Although it may greatly improve the browser responsiveness with slower hard drives, it adds quite a lot of overhead to the cold start-up time. Subsequent launches are fast since all the cache is preloaded in the tmpfs drive.

Firefox needs to change the location of the disk cache in order to achieve this goal. Go to about:config and change this value: browser.cache.disk.parent_directory to /dev/shm/firefox-$USER/ where $USER is the output of id -nu in your user terminal. If browser.cache.disk.parent_directory does not exist, add it as a new String value.

The Google Chrome launcher works out of the box. The cache is limited to 512 MiB. If you need more cache, change the hard-coded value from the chrome-launcher script.

It is recommended to change the swappiness value to 0 in order to keep the tmpfs in memory instead of sending it to the swap. A tmpfs is not guaranteed to live entirely in the memory, therefore the swappiness value may improve the latency.

#!/bin/bash
USER=$(id -nu)
CACHE="/home/$USER/.cache/google-chrome/Default/Cache"
MEDIA="/home/$USER/.cache/google-chrome/Default/Media Cache"
MCACHE="/dev/shm/chrome-$USER/Cache"
MMEDIA="/dev/shm/chrome-$USER/Media Cache"
# prep the cache dir
mkdir -p "$MCACHE"
chmod -c 700 "$MCACHE"
mkdir -p "$MMEDIA"
chmod -c 700 "$MMEDIA"
# sync from disk
rsync -avz --delete "$CACHE"/* "$MCACHE"
rsync -avz --delete "$MEDIA"/* "$MMEDIA"
/opt/google/chrome/google-chrome --disk-cache-size=402653184 --disk-cache-dir="$MCACHE" --media-cache-size=134217728 --media-cache-dir="$MMEDIA" "$@"
# sync from memory
rsync -avz --delete "$MCACHE"/* "$CACHE"
rsync -avz --delete "$MMEDIA"/* "$MEDIA"
# don't forget to
sync
exit 0
#!/bin/bash
USER=$(id -nu)
PROFILE_DIR=$(cat /home/$USER/.mozilla/firefox/profiles.ini | grep -E "\.default" | cut -d "=" -f 2)
DISK=/home/$USER/.mozilla/firefox/$PROFILE_DIR/Cache
MEMORY=/dev/shm/firefox-$USER/Cache
# prep the cache dir
mkdir -p $MEMORY
chmod -c 700 $MEMORY
# sync from disk
rsync -avz --delete $DISK/* $MEMORY
# launch the browser
/usr/bin/env firefox "$@"
# sync from memory
rsync -avz --delete $MEMORY/* $DISK
# don't forget to
sync
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment