Monday, August 12, 2013

Speed up your browser with a RAMDisk.

So I stumbled upon this blog post the other day claiming to speed up your browser by 20%... That seems like a lofty claim, but who am I to balk at a potential 20% savings!

After reading the post, I knew I didn't want to use a utility to create a RAMDisk, as I know how easy it is in Linux! I also didn't like the idea of having to update every shortcut and context just to get Chrome working. So, in the end, this is a hybrid of Sebastian's approach, designed for the Linux power user.

I will give this word of warning though. We will be editing a couple critical system files here, so use extreme caution!

Create your RAMDisk:
For me, I was actually able to skip this step. I have already created a RAMDisk while optimizing my SSD. But for the sake of everyone reading, I'll spell out the steps here.

First things always first... backup the file you are about to edit:

sudo cp /etc/fstab /etc/fstab.bak

Now, lets open it:

sudo gedit /etc/fstab

At the very bottom of the file, add a new line and insert the following:

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

Then, just save and restart!

Your /tmp directory is now living on it's very own RAMDisk! Enjoy the speed benefits! Now, lets get on to the browsers.

Firefox:
Firefox is comparably easy. A simple configuration change and you are all set. In the address bar, Type the following:

about:config.

You may need to click on a button with the text "I'll be careful, I promise!" before proceeding.

Next, right click the body and choose: New -> String.

When it asks you for the preference name, enter:

browser.cache.disk.parent_directory

Click OK and it will ask you for the value, enter:

/tmp/firefox

Don't worry, the firefox directory will be created for you automatically. Restart Firefox.

Chrome:
Chrome is a bit trickier... There are not any general configuration files to get chrome to run on the RAMDisk. Most people suggest you append your chrome shortcuts with the option: --disk-cache-dir="/tmp/chrome". My problem with this is that it is not a holistic solution. What happens if you miss one of potentially several links? What happens if you launch it from the command line? The solution is simple... Symlinks! In your command line, type:

Results?
While I don't have any concrete data, I can tell you that everything feels faster! Load time of the browser is lightning fast! Clicking the back button is much faster (loading the history from ram instead of your harddrive). If anyone has ideas on running, even simi-scientific tests on this, I'd be happy to take that on.

Side effects?
As you may or may not know, RAMDisks are volatile. This means, when you computer restarts, the data held in memory is erased. Anything your browser stores in these cache folders will be lost with each computer restart. I came across one post in my research (I'm sorry, I haven't been able to find it again to link here) that mentioned this can slow down re-visits to you favorite sites by having to re-cache the incoming files, every time you restart. This is not a problem for my tower, as I rarely restart, and I have a UPS which prevents *most* power related restarts. For my laptop, that might be another story. I'll keep you posted if I end up disabling these options in the future.

Another potential concern is loss of ram availability. For me, I have 6GB of ram on my laptop and 8GB on my desktop. While I have on rare occasion come close to that limit, even under heavy utilization, I have still not reached pagefile territory. Besides, the beautiful thing about tmpfs is that is only uses what it needs. Also, I do everything from the browser these days, so any increase in speed there is a win for me!

All of this has got me thinking... what else would benefit from being moved to a ramdisk? I know scratch disks for programs like gimp and other audio/video/rendering/imaging software suites would all benefit, but what else do you think would make a difference?