PDA

View Full Version : How-to: Firefox speedup using SQLite VACUUM command


TheLions
March 5th, 2009, 06:51 PM
my friend of mine found out that Firefox can run faster if it's database is purged of empty entries. Firefox database is using SQLite to manage its database

you'll need:
1)SQLite >=3.0
you can check your version by typing in CLI sqlite3
(exit typing .exit)
if you don't have it you can obtain it here: http://www.sqlite.org/ or with sudo apt-get install sqlite3

2)you'll need this script:
#!/bin/bash

username=$(whoami)
proc="$(ps aux | grep $username | grep -v $0 | grep firefox | grep -v grep)"
if [ "$proc" != "" ]
then
echo "shutdown firefox first!"
exit 1
fi

curdir=$(pwd)

for dir in $(cat ~/.mozilla/firefox/profiles.ini | grep Path= | sed -e 's/Path=//')
do
cd ~/.mozilla/firefox/$dir 2>/dev/null
if [ $? == 0 ]
then
echo "i'm in $(pwd)"
echo -e " running...\n"

for F in $(find . -type f -name '*.sqlite' -print)
do
sqlite3 $F "VACUUM;"
done

echo -e "done in $(pwd) ...\n"
else
echo -e "\n !!!! Nisam uspio uci u direktorij $dir, preskacem ga !!!!\n"
fi
done
echo "Job finished";

cd $curdir

use gedit (or any other text editor) to paste text in it,then save it in your home folder. Open your home folder, right-click on it, select properties. Then select Permissions tab and check the "Allow executing file as program" click Close.

Then close Firefox and run your script from terminal using ./name_of_script

when script done it's work start Firefox and you should feel the difference!;)

batharoy
March 8th, 2009, 04:04 AM
This worked really good for me, thanks.

vasiauvi
March 8th, 2009, 06:16 AM
Yes, I really see a difference!Thanks!

aktiwers
March 8th, 2009, 01:56 PM
Seams to have done a bit here too..

What really made my browsering faster was adding:
export MOZ_DISABLE_PANGO=1

to the end of .bashrc.

gedit .bashrc

And the line at the end

stormtrooprdave
March 8th, 2009, 03:20 PM
In what area should I be seeing speed increase? Page loading? Startup? I don't see any difference but I don't know what I should be looking for.

tehforum
March 8th, 2009, 03:28 PM
Will this work with Firefox 2?

androidkerra
March 8th, 2009, 07:15 PM
whoa!!! very nice how-to bro..tried it and it worked, when i open firefox i already felt the power :D

awesome!!!

binbash
March 9th, 2009, 05:44 AM
Working perfect

TheLions
March 9th, 2009, 05:56 AM
In what area should I be seeing speed increase? Page loading? Startup? I don't see any difference but I don't know what I should be looking for.

it affects on Startup, Smart Location Bar, History, bookmarks...

Will this work with Firefox 2?

Firefox 2 also uses SQLite databases so it should work

itisbasi
March 9th, 2009, 06:24 AM
Should I run the script before starting every new session of Firefox?

zika
March 9th, 2009, 06:29 AM
thanks, it worked, nice addition to my alias that daily updates Minefield ... ;)
hvala.

TheLions
March 9th, 2009, 06:41 AM
Should I run the script before starting every new session of Firefox?

i think it's not necessary, once in month should be fine! ;)

hvala.
nema na čemu! (You welcome!)

jjte
March 9th, 2009, 09:36 PM
Hey what's that error message say near the end of the script? I think it's in Croatian, but I'm not sure.

TheLions
March 10th, 2009, 07:52 AM
Hey what's that error message say near the end of the script? I think it's in Croatian, but I'm not sure.

yes it is Croatian, I forgot to translate it.

"Nisam uspio uci u direktorij $dir, preskacem ga" means
"Error while entering directory $dir"

vegetarianshrimp
March 30th, 2009, 06:50 PM
good howto..thanks

ewaguespack
March 30th, 2009, 08:22 PM
shorter version.



find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;

U-Bom-2
April 25th, 2009, 07:40 PM
maybe sounds noobish and yes i am, but i dont understand this first step! lol can someone explain it more detailed? where do i need to write this or what i need to do

[QUOTE=TheLions;6845423]
1)SQLite >=3.0
you can check your version by typing in CLI sqlite3
(exit typing .exit)

Thanks

TheLions
April 26th, 2009, 10:11 AM
maybe sounds noobish and yes i am, but i dont understand this first step! lol can someone explain it more detailed? where do i need to write this or what i need to do


1)SQLite >=3.0
you can check your version by typing in CLI sqlite3
(exit typing .exit)

Thanks

you need to open your Terminal (Programs-->Acessories->Terminal or Alt+F2 then type terminal)
and write it there.

then you need to run script. If you get stuck just ask!

U-Bom-2
April 26th, 2009, 10:33 PM
ohh lol, i dont got what was CLI :) Thanks

Andy06
May 31st, 2009, 08:33 PM
Umm it sort of bothers me why this works :)?

What does it get rid of? If the gunk we got rid of was so unnecessary, why was it there in the first place?

Are we sacrificing some functionality or covenience by running this script?

Thanks a lot

TheLions
June 1st, 2009, 03:58 AM
Umm it sort of bothers me why this works :)?

What does it get rid of? If the gunk we got rid of was so unnecessary, why was it there in the first place?

Are we sacrificing some functionality or covenience by running this script?

Thanks a lot

When an object (table, index, or trigger) is dropped from the database, it leaves behind empty space. This empty space will be reused the next time new information is added to the database. But in the meantime, the database file might be larger than strictly necessary. Also, frequent inserts, updates, and deletes can cause the information in the database to become fragmented - scrattered out all across the database file rather than clustered together in one place.

The VACUUM command cleans the main database by copying its contents to a temporary database file and reloading the original database file from the copy. This eliminates free pages, aligns table data to be contiguous, and otherwise cleans up the database file structure.

The VACUUM command may change the ROWIDs of entries in tables that do not have an explicit INTEGER PRIMARY KEY.

VACUUM only works on the main database. It is not possible to VACUUM an attached database file.

The VACUUM command will fail if there is an active transaction. The VACUUM command is a no-op for in-memory databases.

As of SQLite version 3.1, an alternative to using the VACUUM command is auto-vacuum mode, enabled using the auto_vacuum pragma. When auto_vacuum is enabled for a database, large deletes cause the size of the database file to shrink. However, auto_vacuum also causes excess fragmentation of the database file. And auto_vacuum does not compact partially filled pages of the database as VACUUM does.

The page_size and/or auto_vacuum mode of a database can be changed by invoking the page_size pragma and/or auto_vacuum pragma and then immediately VACUUMing the database.

http://www.sqlite.org/lang_vacuum.html

Gen2ly
June 1st, 2009, 06:19 AM
After having used firefox quite a bit I noticed this did make a difference. Thanks for the tip.

gregh7470
June 24th, 2009, 09:56 PM
Should I run the script before starting every new session of Firefox?
nah....that's not necessary...and it does work, especially on start up and revisiting pages I've already been to - thx

Elep.Repu
June 25th, 2009, 09:39 AM
I ran the script after I closed ff,
terminal said it was in the settings directory, and said it was working,
but after about 5 minutes I got tired of it and closed the terminal, and did not notice any difference.

TheLions
June 25th, 2009, 09:42 AM
I ran the script after I closed ff,
terminal said it was in the settings directory, and said it was working,
but after about 5 minutes I got tired of it and closed the terminal, and did not notice any difference.

did script finished before closing terminal?

If not, it seems that your profile is huge so it needs a lot of time to complete. Try leaving it for 20 minutes or more.

harecanada
June 25th, 2009, 02:07 PM
Thanks to The Lions!! This worked really good without a hitch.

harecanada

zika
June 25th, 2009, 02:21 PM
Just to say that I'm using the following alias to do the job:
alias cff='find ~/.mozilla/firefox-3.5/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \; && find ~/.mozilla/firefox-3.6/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \; && find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;'Same thing in different packaging ... :) Yes, I have all 3 versions active ... :) Just put it in ~/.bash_aliases and addif [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fito ~/.bashrc to enable use of separate file to store aliases.

Andrew.Z
July 1st, 2009, 11:25 PM
You don't need command line ninja skills: BleachBit vacuums Firefox (http://bleachbit-project.appspot.com/features/) (and performs other cleaning tasks) from a GUI with just a click. It's in the Ubuntu 9.04 repositories, but the repo has an old version, so the link above has a newer Ubuntu package.

danbuk
July 4th, 2009, 06:36 AM
:p thx a lot broo.....
i see that diffrence than before.....

danbuk
July 4th, 2009, 06:42 AM
bro...i wanna ask about something...
what will happen if i hidding that programs..it still run or not ?
thanks a lot..

TheLions
July 4th, 2009, 03:22 PM
bro...i wanna ask about something...
what will happen if i hidding that programs..it still run or not ?
thanks a lot..


I can not understand you very well.
If you are asking me would script work while firefox running, answer is no.

Fred Better
July 13th, 2009, 09:04 AM
Thanks for the hints. Here's my version
#!/bin/bash
username=$(whoami)

function check_app {
proc="$(ps aux | grep $username | grep -v $0 | grep $1 | grep -v grep)"
if [ "$proc" != "" ]
then
echo "!!! Shutdown $1 first!"
exit 1
fi
}

function vacuum_mozillas {
echo "Vacuuming $1..."
find $2 -type f -name '*.sqlite' -exec sqlite3 -line {} VACUUM \;
}

check_app firefox
check_app thunderbird
vacuum_mozillas firefox ~/.mozilla/firefox/
vacuum_mozillas thunderbird ~/.thunderbird

echo 'Done!'

cwhisperer
July 22nd, 2009, 04:20 AM
Thanks for the hints. Here's my version
#!/bin/bash
username=$(whoami)

function check_app {
proc="$(ps aux | grep $username | grep -v $0 | grep $1 | grep -v grep)"
if [ "$proc" != "" ]
then
echo "!!! Shutdown $1 first!"
exit 1
fi
}

function vacuum_mozillas {
echo "Vacuuming $1..."
find $2 -type f -name '*.sqlite' -exec sqlite3 -line {} VACUUM \;
}

check_app firefox
check_app thunderbird
vacuum_mozillas firefox ~/.mozilla/firefox/
vacuum_mozillas thunderbird ~/.thunderbird

echo 'Done!'

had to replace vacuum_mozillas thunderbird ~/.thunderbird with
vacuum_mozillas thunderbird ~/.mozilla-thunderbird

and works like a charm ;) great job

The Real Dave
September 6th, 2009, 09:10 AM
Didn't really see much of an improvement to be honest, opened .2 seconds faster. Gereral operation was a bit quicker, but not much. My install is only about a week old though, so that could be why.

Barriehie
October 23rd, 2009, 08:12 PM
Should I run the script before starting every new session of Firefox?

I added mine to the crontab file to be run before my twice a week backups.

Barrie