Tuesday, February 26, 2008

Gmail IMAP + Apple Mail + lots of messages = Constant disk activity

January 21, 2009 – See update at the bottom for a solution to this issue.

I am a long time Gmail user, but have started using Apple Mail with Gmail over IMAP just a few weeks ago. Lately I noticed that:
  1. The disk activity is almost constant while Mail is running.
  2. Mail is constantly synchronizing and downloading messages from the
    server.

The almost constant disk activity is the most annoying issue, as all the applications feel sluggish when Mail is heavily using the disk, as if the machine was swapping. I can see the constant activity of Mail with fs_usage -w -f filesys Mail.

Message synchronization is causing lots of downstream network traffic (constantly about 20-30 KB/s). As annoying as this is, with a pretty good connection, this level of network traffic doesn't have as much immediate impact as heavy disk activity.

A few data points:

  • My All Mail contains more than 110,000 messages, about 2.4 GB or 35% of the Gmail quota.
  • My ~/Library/Mail folder weighs a little more than 5 GB.
I haven't found any good solution to this issue yet. If you also have this problem, here a couple of workarounds:
  • Exit Mail when you are not using it. (I had to state the obvious.)
  • To avoid exiting and starting Mail, you can stop the process and resume it. To stop it run killall -STOP Mail, to resume it run killall -CONT Mail. Some applications don't like being stopped and resumed; I haven't noticed any negative side effects with Mail, but use this at your own risk.
And of course, if you have a hint or advise, please post a comment here. I will make sure to update this post if I hear about a solution.

A Solution
Go to the Mail.app preferences. Under Accounts, go the Advanced tab. Then, in the Keep copies of messages for offline viewing drop-down, select Only message I've read.
This will drastically cut on the amount of data that Mail.app stores locally, and it solved the slowness, high disk activity, and hanging issues I had with Mail.app. Of course, this method has a few downsides:
  • You won't be able to use Spotlight to search through the body of your messages. (Which is fine for me, as I found Spotlight to create other performance problems, and I had it disabled anyway.)
  • You won't be able to access some of your emails when offline. (The next time you do email on a flight, you might find that some emails you haven't already read have not been downloaded.)
  • Mail.app will only download the body of a new message when you click on it, which adds a little lag. (Before, Mail.app was downloading new messages in the background, so when you were clicking on a new message, that message was already there and no network activity was necessary to show the message. Ideally, I'd like to tell Mail.app "only download messages that arrive in my inbox".)