Back to Home

Overclocking Firefox with TmpFS

firefox · how to · geek

Overclocking Firefox with TmpFS

    Firefox uses SQLite to store most of the service information, which makes its work noticeably slower. While accessing its SQLite database, Firefox “freezes” when other processes in the system actively use IO-operations with the disk.
    However, there is a solution for migrating a Firefox profile to a RAM partition using TmpFS.

    Note: this solution was proposed in this forum. I just slightly modified it and present it to the public for a solution that uses rsync to synchronize the Firefox profile between RAM and the hard drive.

    So, we will prepare our profile, make it easier. The following changes to the FF settings are suggested in the source (by navigating to about: config in FF):
    set browser.cache.disk.capacity to 20000
    set browser.safebrowsing.enabled to false
    set browser.safebrowsing.malware.enabled to false

    * This source code was highlighted with Source Code Highlighter.

    Then copy our profile to another directory. By default, the profile is in ~ / .mozilla / firefox / and looks like xxxxxxxx.default.
    Create a new directory, naming it profile, then copy the contents of your real profile (xxxxxxxx.default) into the created profile folder.
    However, before that, delete the files of the form urlclassifier * .sqlite in the profile and clear the browser cache.
    cd ~/.mozilla/firefox/
    mkdir profile
    cd xxxxxxxx.default/
    rm -f  urlclassifier*.sqlite
    cd ../
    cp -r *.default/* profile/

    * This source code was highlighted with Source Code Highlighter.


    Note: it is understood that you have one Firefox profile. If a few - do not worry, this guide is easy to apply to other Firefox profiles.
    In the future, we will keep in mind that we use the profile xxxxxxxx.default , however, in practice, replace it with the name of your profile in Firefox.
    The same applies to the username in the system: in this manual, the name xxxx is used , which in practice implies the name of your user in the system.

    So, we proceed to the most interesting part.

    Create a RAM partition.


    Add the following line to the / etc / fstab file :
    firefox /home/xxxx/.mozilla/firefox/xxxxxxxx.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=1000 0 0

    * This source code was highlighted with Source Code Highlighter.

    Of course, change the values ​​according to your username, Firefox profile directory, and your uid and gid on the system.

    Testing a profile in RAM


    Now we need to close Firefox, so it’s worth remembering (or writing down) the following steps.
    So close Firefox. Then make sure that your current profile is actually copied to the ~ / .mozilla / firefox / profile / directory . Now clean your original profile directory, i.e. just make it empty:
    cd ~/.mozilla/firefox/
    rm -Rf *.default/*

    * This source code was highlighted with Source Code Highlighter.


    Before we start Firefox, we need to mount the RAM partition, then copy the contents of the profile to the mounted partition. At the same time, you need to do regular copying back from the RAM section to the profile directory on the disk. Otherwise, you risk being left without profile data when you turn off the computer.
    To avoid this, we use rsync (a much better solution than tar [Approx. Author]). We will create a small script that checks for the presence of our profile in RAM (unpacked file). If this is not the case, we mount the RAM partition and copy our profile into it. If the profile is present in RAM, we synchronize the profile directory on the disk with the profile in RAM.
    So, here is the script text (let's call it tmpfs_firefox.sh ):
    #!/bin/bash

    # Измените на соответствующее имя профиля
    PROFILE="xxxxxxxx.default"

    cd "${HOME}/.mozilla/firefox"

    if test -z "$(mount | grep -F "${HOME}/.mozilla/firefox/${PROFILE}" )"
    then
      mount "${HOME}/.mozilla/firefox/${PROFILE}"
    fi

    if test -f "${PROFILE}/.unpacked"
    then
      rsync -av --delete --exclude .unpacked ./"$PROFILE"/ ./profile/
    else
      rsync -av ./profile/ ./"$PROFILE"/
      touch "${PROFILE}/.unpacked"
    fi

    exit

    * This source code was highlighted with Source Code Highlighter.

    So Firefox is closed. Run the script for the first time. He will mount the partition in RAM and copy our prepared profile into it.
    If you now look at the profile directory, you will see all the necessary profile files:

    ~/tmpfs_firefox.sh
    ls ~/.mozilla/firefox/*.default/

    * This source code was highlighted with Source Code Highlighter.


    Run our script a second time. Thus, we synchronize the profile saved on the disk with the profile in RAM:
    ~/tmpfs_firefox.sh
    # Вы увидите нечто вроде:
    #  building file list ... done
    #  sent 36643 bytes received 20 bytes 73326.00 bytes sec
    #  total size is 45390178 speedup is 1238.04

    * This source code was highlighted with Source Code Highlighter.


    Now the climax: testing Firefox.


    First, make sure that the profile has been mounted correctly in the RAM section. If you want, you can try to unmount the RAM partition and run our script again. If everything is smooth and your profile is in good condition, mounted - just run Firefox.
    I hope you feel that it is now working much faster. Perhaps this is more noticeable with the so-called chip "smart bar auto completion": the results of the addition should be displayed instantly.
    Nevertheless, we need regular profile synchronization between the disk and RAM. We can do this when we exit the system, however, such a solution is not reliable enough. Since we use rsync for synchronization, you can run it quite often. We use cron for this task: we will run the script every 5 or 10 minutes.
    Thus, even if your computer shuts down suddenly, you will always have a fresh profile saved a couple of minutes ago.
    crontab -e
    */5 * * * * $HOME/tmpfs_firefox.sh

    * This source code was highlighted with Source Code Highlighter.

    For added convenience, create another small script to launch Firefox. It will check if the RAM profile is loaded before loading Firefox. You can use this instead of the usual Firefox launcher shortcut:

    #!/bin/bash
    ~/tmpfs_firefox.sh
    firefox &
    exit

    * This source code was highlighted with Source Code Highlighter.


    The results.


    We haven’t done so much:
    • regular backup of Firefox profile
    • wrote a script that mounts a regular profile from disk to RAM
    • provided fairly reliable profile synchronization between RAM and the hard drive.
    • every 5 minutes our profile is saved from RAM to a directory on disk.

    Sure, Firefox should just work as before. However, it is much faster than before. At the price of only 128 megabytes of RAM!

    Source: verot.net

    PS However, it works as described. Why translated :)

    Read Next