After more research, I've found that there exists an API for GMail: https://developers.google.com/gmail/api/ I don't think that API was released when I posted this question back in 2013.
Using that API, I have created a demo program that fetches the 100 last mails of a label: https://gist.github.com/bjourne/37a9d15b03862003008a1b0169190dbe
The relevant part of the program is:
resource = service.users().messages()
result = resource.list(userId = 'me', labelIds = [label]).execute()
mail_ids = [m['id'] for m in result['messages']]
start = time()
mails = []
batch = BatchHttpRequest()
cb = lambda req, res, exc: mails.append(to_mail(res))
for mail_id in mail_ids:
get_request = resource.get(**headers_params(mail_id))
batch.add(get_request, callback = cb)
result = batch.execute()
print('Took %.2f seconds' % (time() - start))
It lists the last 100 messages sorted by date in a label (folder in IMAP terminology) containing over 570k messages.
On my machine, this loop takes about 0.5 - 0.8 seconds. I can claim confidently that no pure IMAP client on the planet comes even close. Likely, IMAP won't ever get faster because it is a poor fit for how Google stores mail internally.
So I'll answer my own question. This is the API they are using and it wasn't exposed earlier.