I'm currently working on some improvements in our code e.g. to make possible to open a folder with 100k messages and make memory_limit to not exceed on this operation.
I've found that we have one optimization for messages listing. It's used when skip_deleted=false and message_sort_col='' and no threading. So, this is a corner case when we don't need to fetch the list of message UIDs nor IDs from server, but we build the array of IDs on range(1, $max), see line 1529 of rcube_imap.php.
This solution is good for performance in this one case, but if we could get rid of it and always work with UIDs only, we would have much simpler code and possibly more performant in other places (including caching) because there would be no need for id-to-uid mapping.
The problem is that in described case we'd need to call UID SEARCH ALL. Even so, I think it's worth to do this. Any thoughts on this?