📜 ⬆️ ⬇️

Firefox overclocking with TmpFS

Firefox uses SQLite to store most of the service information, which makes it noticeably slower. While accessing its SQLite database, Firefox "freezes" when other processes in the system actively use IO disk operations.
However, there is a solution for moving the 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 a decision that uses rsync to synchronize the Firefox profile between RAM and the hard disk.

So, we will prepare our profile, make it easier. The source suggests the following changes in the FF settings (by going 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, calling it profile, then copy the contents of your real profile (xxxxxxxx.default) into the created profile folder.
However, before this, delete the files of the urlclassifier * .sqlite type 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 assumed that you have one Firefox profile. If a few - do not be upset, this guide is easily applied to other profiles of Firefox.
In the future, we will keep in mind that we use the xxxxxxxx.default profile, but in practice replace it with the name of your profile in Firefox.
The same is true for the user name 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 partition RAM.


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, the Firefox profile directory and your uid and gid in the system.
')

We test a profile in RAM


Now we need to close Firefox, so it’s useful to remember (or write down) the following steps.
So close Firefox. Then make sure that your current profile is actually copied to the ~ / .mozilla / firefox / profile / directory. Now clear 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 launch Firefox, we need to mount the RAM partition, then copy the contents of the profile to the mounted partition. At the same time, it is necessary to make regular back copies 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, use rsync (a much better solution than tar [Author's Note]). We will create a small script that checks 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. This way 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 culmination: we test Firefox.


First, make sure that the profile was correctly mounted 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 proper condition, mounted - just launch Firefox.
I hope you feel that it works much faster now. Perhaps this is more noticeable with the so-called “smart bar auto completion” chip: the results of the addition should appear instantly.
Nevertheless, we need regular synchronization of the profile between the disk and the RAM. We can do this when logging out, but this solution is not reliable enough. Since we use rsync for synchronization, we 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 suddenly turns off, 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 .

To make things more comfortable, we will 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 launch shortcut:

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


* This source code was highlighted with Source Code Highlighter .


Results


We didn't do that much:

Undoubtedly, Firefox should just work as before. However - much faster than before. At the cost of only 128 megabytes of RAM!

Source: verot.net

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

Source: https://habr.com/ru/post/48367/


All Articles