This is the second of the two optimizations I described a while ago, and brings my inbox search down to 1.811 seconds, 2.5X faster than it was originally. This optimization is based on the observation that Xapian decompresses a document's term list every time you iterate over it. As a result, notmuch can decompress the beginning of a single term list quite a few times. This patch series combines all of this into a single pass that is only slightly more expensive than fetching one metadata field used to be, but offers a huge win in the common case where a message object is used for multiple metadata fields.