Pre-scan histories for predicates before filtering

This improves efficiency by scanning histories to see if they actually need to be filtered before filtering them.