Thursday, September 4, 2008

Mozilla Firefox in "Jelly mode"

In case your are using a Netbook with an Solid-state drive (SSD), like the Asus EeePC 901, you will notice that Firefox 3 from time to time behaves like being in "jelly mode": it stops responding for a few seconds and simply freezes. Although this "jelly mode" will only last a few seconds, it will drive you mad if you try to use it for more than five minutes. Fortunately this can be fixed with some easy tricks and less than 10 minutes of time.

We got reports about this issue from several users of X-Setup Pro and they all asked us if there is a way to make Firefox faster and get rid of this jelly mode. Since we couldn't explain why this would happen, and we wanted to test X-Setup Pro on a netbook anyway, we bought a EeePC 901. After doing the typical "original setup, driver download and install, Windows Update check" procedure we installed Firefox 3.01 and within the first five minutes we were experiencing the jelly mode as well.

With the help of Process Monitor, DriveGLEAM, Wikipedia and mozillaZine we are pretty sure what this is causing. While using Firefox, it will perform a lot of small write operations to several SQlite databases (e.g. urlclassifier2.sqlite or places.sqlite) and other files like configuration files of add-ons or files for the cache. While this is fine with a normal HD, this causes a lot of stress for an SSD. SSDs are fast when reading data but very slow when writing. Although Firefox will only perform small write operations the SSD is not fast enough to perform this in time and causing Firefox to wait. And this is exactly what we are calling the "Firefox jelly mode".

The solution is quite simple: Move the Firefox profile (where all these write operations take place) to a location that is faster. But: The EeePC 901 only has two SSDs (C: and D:) plus an SD slot, meaning that there is no fast location available. This means, the only solution that is left is a RAM disk. The people at My Digital Life have written about this some weeks ago and made a package we can use right away.

Download the package and extract it to a folder on your HD (SSD), e.g. C:\ProgramFiles\RamDisk. From there, start RAMDISK.exe and click on the right on Install Ramdisk.

After a few seconds, the controls on the left will be selectable and we can choose which size this RAM disk should have. Since the 901 I'm using has 2 GB of memory, I selected 128M (128 MB) for size, if you netbook as only 1 GB, you might want to use 64 MB. All other settings (Drive: R:, Fixed Media) remain unchanged. Click OK and the program should report Success.

The next thing we need to do is to prepare the RAM disk, since it is currently set to use FAT instead of NTFS. Create a new Batch file in the same folder where RAMDISK.exe is located and name it Setup.bat. This batch will create some folders and save the image (with the folders) to the registry. Since we are using a RAM disk, rebooting the computer will wipe the entire contents of the R: drive. With the batch, we are creating an image of the drive and store it to the registry. When the computer is booted, the RAM disk is re-created from this image automatically.

@echo off

echo This will setup the RAM Disk

format /FS:NTFS /Q /V:RamDisk /A:512 R:
chkdsk /L:2048 R:
CACLS R:\ /G Administrators:F

MKDIR R:\Stuff

rdutil R: registry


Execute the batch. Press return to get things rolling, then enter RamDisk to confirm you want to format the R: drive, confirm the format again (Y) and once again (Y). If you now open Explorer, you should have an R: drive with several folder in it. Please note: If you ever change your mind about the size of the RAM disk and change it using RAMDisk.exe you need to execute this batch again!

Next, we need to create a profile in Firefox that will be stored on the RAM disk. Using Explorer, open R:, change to the folder Stuff and create a new folder named RamDiskProfile. Now open a command prompt (Start - Run - cmd.exe) and change to the path where Firefox is installed, e.g. cd "c:\program files\Mozilla Firefox". Execute firefox.exe -ProfileManager. Click on New profile and enter as name RamDiskProfile. As folder, select R:\Stuff\RamDiskProfile. Back in the profile selection, click Start Firefox.

If everything works as expected, you should see the Welcome to Firefox page. Notice: Do not, repeat, DO NOT copy your existing profile! At least on my 901, several files inside the profile had direct likes in it (e.g. C:\Documents and Settings\TeX HeX\...). If you simply copy your existing profile you will end up having some of the files will be written on the SSD again.

What we now need to do is to change the location where this Firefox profile will put the cache files to. In the address bar, type about:config and confirm the warning that appears. Right-click anywhere in the list and select New -> String. As name of the new value type browser.cache.disk.parent_directory. As value for it, type R:\FFCache. Close Firefox.

Now we will create a backup of this profile to the SSD. Use Start -> Run again and type %APPDATA%, which will display the folder where your personal data is normally saved. Open the folder Mozilla, then Firefox and then Profiles. Copy the folder R:\Stuff\RamDiskProfile there.

Okay, we are almost there. Create a new batch file that is used to start Firefox with the profile from the RAM disk. It will copy the files from the RamDiskProfile (from %APPDATA%) to the R: drive, wait for Firefox to exit (= you are done with browsing) and copy then any files that were changed back to %APPDATA%.

@echo off
echo Launching Firefox from RAM disk...

IF NOT EXIST R:\Stuff\RamDiskProfile\. mkdir R:\Stuff\RamDiskProfile

REM The xcopy command is one line until the "cd" command
xcopy "%APPDATA%\Mozilla\Firefox\Profiles\RamDiskProfile\*.*" "R:\Stuff\RamDiskProfile" /S /I /Y /H /Q
cd /D "R:\Stuff\RamDiskProfile"
attrib -a *.* /S

echo Firefox launched, this window will close when Firefox is closed
start /wait "Firefox from RAM disk" "%ProgramFiles%\Mozilla Firefox\firefox.exe" -profile R:\Stuff\RamDiskProfile

echo Copying files back from RAM disk...
REM The xcopy command is one line
xcopy "R:\Stuff\RamDiskProfile\*.*" "%APPDATA%\Mozilla\Firefox\Profiles\RamDiskProfile" /S /I /Y /H /Q /M

Now you also know why we have changed the location of the cache files earlier on: Because the cache files are now longer part of the profile (but instead on R:\FFCache), they don't need to be copied back. Of course, if you want to have your cache persistent, you can easily delete the browser.cache.disk.parent_directory from about:config and the cache files will be copied as well.

Start the batch file and give it a try, I'm pretty sure you will think you have just got a new computer. No more jelly mode, and the speed is what you were expecting from Firefox.

To verify that everything has worked, type about:cache into the address bar and look at the two cache directories, both should be pointing to R. One thing you need to keep in mind: In case you install an add-in or a theme, Firefox is offering to restart it with a single click. Don't do this since the batch will close when Firefox exists. Simply close it manually and restart it again using the batch.

Some other things you can do with the RAM disk: There is already a folder called TEMP so you can simply reconfigure your environment variables TEMP and TMP to use this folder. And finally, the folder IECache can be used to put the temporary internet files there.



  1. For some reason, this just does not work for me. It works fine the very first time I open up Firefox after I finish through with this tutorial, but after I close Firefox and open it up again, a pop-up message appears that says something to the likes of "Firefox cannot open because it is currently being used. Close Firefox or restart your system."

    I "firefox.exe -profilemanager" in cmd and unchecked "Don't ask at startup" Then I opened Firefox again, created a new profile to a folder not in the RamDisk, and it works fine. But whenever I create a new profile to a folder in R:, a pop-up message says, "Firefox cannot use the profile '[Name of Profile]' because it is in use.

    It might be because I installed Firefox on D:\Program Files instead of C:\Program Files so I might have made some mistakes in following the tutorial.

  2. This is strange. Although I doubt it, is it possible that your anti-virus software is somehow messing around with the profile? Maybe you should exclude R:\Stuff\RamDiskProfile from the AV scan. Also, I have done this with FF 3.0, are you maybe using an older version?

  3. Many thanks for this - Firefox is slow much quicker now on my Acer Aspire One. Will be sharing this with people on my blog.

  4. Great !!!
    On my 901, this jelly mode was very annoying. But now it's great, thank you very much.
    Another trick : with the batch file used to launch FF, you have this black command window showing now... A way to hide it : use a VBScript to launch the batch to launch FF o_o'.
    Here is the code, paste it into a LaunchFirefox.vbs file for example :

    Set shell = CreateObject("WScript.Shell")

    shell.Run """D:\RamDisk Apps\Firefox.bat""", 0, True

    where 0 means hide the window, and True waits for the end of the command. You have to give the full path for the batch.
    Enjoy, now it's totally transparent to use ramdisk and batch, even more if you map the vbs file with an Instant Key (b registry because the GUI only accepts exe):

    - go to the registry HKCU\Software\Asus\EeePC\ASUSACPI
    - "QuickKey4" = wscript.exe "D:\Ramdisk Apps\LaunchFirefox.vbs"

    and there you go !

  5. Great article. However in the second batch file where Firefox is started. You do not need to copy the entire folder over to the ramdisk every time the ap is started. Only once, when it is first started. From that point on the data resides on the ram drive, unless you delete it manually of course. Copying back to the drive is necessary though. Using a goto statement when the folder is checked to see if it exists and jumping the copy operation if it does at the front, should save a bit of startup time.

  6. @jbhb12: Yes, you are right this would speed up the script even more.

    I usually start FF only once in a session (and keep it running) so I didn't realized this improvement.

    I guess the line

    IF NOT EXIST R:\Stuff\RamDiskProfile\prefs.js xcopy ....

    would do the trick.

  7. Thank you! You're welcome to grab a beer or THREE in my fridge!

  8. Thank you, Sir! It's just like Firefox got an entirely new engine.