I’m not using Mail.app on OS X these days (opted for MailMate), but I received an email from Mathias Törnblom updating the database vacuuming trick I’d posted previously. It makes the script work for Mail on El Capitan, and maintains backward compatibility.
The code below will quit Mail, vacuum the SQLite index, then re-open Mail. On a large email database that hasn’t been optimized for a while, this can provide significant improvements in responsiveness and speed. To use the script, copy and paste it into a new document in Script Editor (make sure the language is set to AppleScript), and save it as a Script (scpt) file. Then you can run it via a launcher (LaunchBar, Alfred, etc.) or via the Scripts menu.