Mac OS X comes with a very usable e-mail client called Mail.app or simply Mail, but it tends to slow down a bit over time, especially when moving around large amounts of e-mails from multiple accounts.
This guide will help you optimize the performance of Mail. I’ve listed
some useful tips for dealing with large hierarchically stored mail
archives. To get the most out of these tips, you’ll want to be using
Mac OS X 10.4 (Tiger) or higher.
Optimizing Mail’s Internal Database
What it does
Mail keeps track of your e-mail messages in several different locations, but the main location is the Library/Mail
folder in your home directory. In this folder you will find every
single e-mail message in each account stored as a separate file.
Spotlight uses these files to keep track of e-mail contents.
Mail additionally stores a so-called Envelope Index
which contains cross references between message subjects, contents and
other interesting aspects. Over time, this index becomes less and less
efficient and slows down Mail.
Luckily, the Envelope Index is stored as a database in a well
known format. This enables you to use tools for optimizing performance,
which sounds a lot more difficult than it really is.
Performing the optimization
Optimizing Mail’s Envelope Index is very simple. Follow these simple instructions to make Mail snappy again:
- Quit Mail from the menu or using Apple + Q and wait until the black arrow disappears from Mail’s Dock icon.
- Open up Terminal using Spotlight via Alt + Space or start it from the Applications/Utilities folder.
- Type or copy the following line into the Terminal window:
sqlite3 ~/Library/Mail/Envelope\ Index vacuum
Finally, press Enter to perform the
action and wait until it finishes, this can take anywhere from a few
seconds to minutes depending on the amount of mail.
What has just happened?
The action performed in the Terminal will clean up Mail’s internal
database, saving disk space and speeding up the application. Dissecting
the action bit by bit reveals the following:
- sqllite3 refers to the command for manipulating the database. Mail uses the SQLite database library which provides the sqlite3 command line tool.
- ~/Library/Mail/Envelope\ Index refers to the actual file in which Mail’s database is stored.
- vacuum refers to the action we want to perform on the database. Vacuuming is jargon for cleaning up unused space in the database and packing the data tightly together.
Of course I tried all this out on my own setup and I measured Mail’s
speed and index size prior to and after optimizing. The results are
Prior to optimization Mail took about ten seconds to start up
and switching to other mailboxes took about as long. The Envelope Index
was 12 megabytes in size, with my Mail folder totaling just around 51
After optimizing the index, Mail starts up in less than one
second and switching mailboxes takes about as much. The Envelope Index
is now 3 megabytes, which is four times smaller than before. My total
Mail library now counts 42 megabytes.
The performance increase is really tremendous and I urge every
Mail user to try this trick out, it will seem as if you have just
bought a new Mac.
Now you might say that my mailbox is relatively small in size
(see the following tip) but I do have more than 5.000 e-mails stored
locally. Even with this dataset, the speedup is very evident.