I'm trying to get a better understanding of the Gmail API. One of the stated benefits of the Gmail API is that it can "deliver dramatic performance improvements over IMAP." What aspects of the Gmail API and protocol allow it to be 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
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.)