Critical performance bug

@Nick-Hall, there is a critical performance bug that I was hoping that it would be included in any of the 6.0.x versions, or 6.1. It is simple looking code that hides a O(n**2) slowdown that can reduce the time every filter is applied. The fix is O(n). Here is the troubled code:

            res = sorted(
                [handle_tuple[handle] for handle in res],
                key=lambda x: id_list.index(x),
            )

It looks banal, but the issue is in the .index() which is O(n). Since it is in the key function, it gets called n times, thus n * n.

I have made the fix twice (I forgot about the first one):

and then:

The first includes another optimization, and the second adds infrastructure to time the parts of filter processing. I like the fix for the bug in the second PR better.

What needs to be done to get this critical fix into the next release?