Vacuum your Firefox Databases for Better Performance

Since Firefox 3.0, bookmarks, history and most storage is kept in SQLite databases. Also, the default history time span was raised from 9 to 90 days as it became more discoverable and useful thanks to the awesome bar, so depending on your browsing habits it could represent some pretty large databases.

Aas any other database, SQLite databases become fragmented over time and empty spaces appear all around. But, since there are no managing processes checking and optimizing the database, these factors eventually result in a performance hit. So, a good way to improve startup and some other bookmarks and history related tasks is to defragment and trim unused space from these databases.

To do this:

  • Step 1: get sqlite3, a single file command line SQLite database manager, for your platform (available for Linux, Windows, and Mac OS X).
  • Step 2: Copy the downloaded binary to your profile folder where all your .sqlite files reside.
  • Step 3: Close Firefox.
  • Step 4: From a command line prompt in your profile folder, run:

sqlite3 [SQLite database] VACUUM

replacing [SQLite database with the name of a SQLite file, like places.sqlite.

On Windows, to defragment all SQLite databases in one command, run:

for %a in (*.sqlite) do (sqlite3 %a vacuum)

I ran the script in a couple of machines resulting in a noticeable reduction of start up times after databases defragmentation:

Machine places.sqlite size before vacuum places.sqlite size after vacuum Cold startup Before Cold Startup After
Machine 1: 1 window, 20 tabs 10 MB 9 MB 11 s 8 s
Machine 2: 3 windows, 25 tabs 40 MB 27 MB 10 s 7 s

So if this is all good, why hasn’t Mozilla included this defragmenting procedure? The thing is they want to but still haven’t found the best way to do so. One of the suggestions so far has been to do it during an update: it has the advantage of been semi regular (about every six weeks), and already interrupts the user workflow (and requires the database files been released, turning Firefox off).

A good option for Windows users is IniFox, by InfoSpyware which simply packs sqlite3 and an interactive batch file that defragments all databases in your profile as described above. You will still have to download and copy, but you will avoid opening a console and repeating the steps for all the databases.

If you try this mechanism, please take some time to get your before and after times and sizes and share your results in the comments. For cold startups, you will have to restart your system to get valid results.

Vacuum Firefox databases for better performance, now with no restart :

A few months ago, I posted how to improve Firefox performance by defragmenting its database files executing SQLite VACUUM command. The only con was that it required a Firefox restart to execute the command.

Thanks to Mozilla’s Jeremy Orem, we have now learned it can be done from within Firefox in two short steps:

  • Open the Error Console: Tools menu/Error Console
  • In the Code text box paste this (it’s a single line):
    Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL("VACUUM");
  • Press Evaluate. All the UI will freeze for a few seconds while databases are VACUUMed

Note however that the procedure optimizes the Places database only, but this is precisely where you will get the most significant performance improvements.

Comments in Jeremy’s blog post point to the open bug on the issue and plans to include this optimization by default, and Vacuum Places, an (experimental) add-on by Revertron that does just this.

Related Posts