Slow IMAP SORT

Ewald Dieterich ewald at mailbox.org
Mon Aug 15 09:43:25 UTC 2022


The following IMAP SORT with 2 sort criteria is very slow on an mdbox 
mailbox with lots of mails (more than 10,000) and an empty cache:

. SORT (ARRIVAL DATE) UTF-8 ALL

Each mail is opened when the SORT is executed, which is slow, given the 
number of mails in the mailbox.

Debug: Mailbox INBOX: UID 1003: Opened mail because: header stream
<repeated for each mail>

Repeating the SORT opens all mails again and again:

Debug: Mailbox INBOX: UID 1003: Opened mail because: header stream
<repeated for each mail>

If I just sort by ARRIVAL, the SORT is fast and I don't see any "Opened 
mail because" messages in the debug log.

. SORT (ARRIVAL) UTF-8 ALL

If I just sort by DATE, the first SORT is slow.

. SORT (DATE) UTF-8 ALL

The debug log looks like this:

Debug: Mailbox INBOX: UID 1003: Opened mail because: header Date (Mail 
has other cached fields, reset_id=1633683216)
<repeated for each mail>

This fills the cache and if I sort by DATE again, the SORT is fast and I 
don't get any more "Opened mail because" messages in the debug log.

If I now repeat "SORT (ARRIVAL DATE)", the SORT is fast, the mails are 
not opened. If I clear the cache, "SORT (ARRIVAL DATE)" goes back to 
being slow, not filling the cache.

This doesn't seem right. "SORT (ARRIVAL DATE)" should also fill the 
cache to execute repeated SORTS faster, right?


More information about the dovecot mailing list