Speed up thread sort when many long threads exist.
Merge request !75 reported a massive slowdown opening a mailbox with
many long threads: on the order of an hour.
This is because mutt_set_virtual() was iterating through the whole
thread for each message.
After taking a closer look at current Mutt behavior, it seems the
num_hidden count is only needed in the root thread. Quoting my
comment in the merge request:
The index-format expando %M only applies to root level headers, so
there are no issues there.
The only concern is the pattern ~v. Limiting always resets collapsed
and num_hidden, so there also can't be any issues there. Tagging and
other pattern operators only work on visible messages. So tagging
while threads are sorted will only tag the root messages of
collapsed threads.
However, if you sort by thread, collapse a thread, and then sort by
date, the collapsed and num_hidden fields are not reset for each
header. In theory this would allow us to tag ~v with date
ordering. However, in master the num_hidden is only set (by
mutt_set_virtual()) for visible messages with a virtual number.
So even in master, switching to date-order and tagging ~v will only
tag the root messages of each collapsed thread.
This commit removes the num_hidden setting in mutt_set_virtual(),
instead directly assigning that value in the roothdr during a collapse
operation.
A subsequent commit will fix the behavior of ~v, when switching
sorting from threaded to something else, by putting num_hidden in
every header in the thread. This is technically a change in behavior,
so I will make that commit in the master branch.
Thanks to Score_Under for the pull request and for testing my
alternate solutions.