What makes the Gmail API more efficient than IMAP?
For example IMAP has the notion of a "mailbox" and supporting that means storing a sequence number for every message. In Gmail's IMAP, since every label is a folder that means we need to keep a sequence of every message in every label. For something like 'All Mail' that could be 1,000,000 messages--hard to keep track of that in the server.
Things like threads, are also foreign to IMAP but native in Gmail. The Gmail backend is optimized to support threads as is the Gmail API. If you want to retrieve all messages in a thread it's a single call in the API.
The dramatic performance improvements is for the use-cases where the API makes sense (like web and mobile applications). If you want to sync the entire mailbox, IMAP may well offer as good, or better, performance given the ability to cache an authenticated connection, etc.
The best way to answer this is to compare the Gmail API docs with the IMAP protocol specification and see what kinds of operations they permit. Anything that lets you
- do more work server-side instead of client-side,
- use fewer round trips,
- send and receive only the particular data you're interested in, or
- cache state locally
is going to give performance improvements.
Some specific examples: (I've merely dabbled in IMAP and have no experience with Gmail API, so my examples may not be valid. Like I said, read the docs for the full story.)
- The Gmail API has built-in support for synchronizing clients, including getting a list of recent updates. Doing this in IMAP is harder.
- Gmail API's searching features appear to be more powerful than IMAP's.
- Gmail API's support for threads appears to be higher-level than IMAP's optional THREAD extension.