This had significant regressions after #6646, so let's import it to track progress and prevent future regressions.