Overhaul flow construction with several performance improvements

This is a grab bag of performance improvements that significantly improve style recalculation, layout, and painting on a few static pages.

Let me know if you'd like me to split this PR up.

r? @glennw
This logic doesn't appear to exist anymore - is thid handled elsewhere?