Fix terrible performance issue in 1.8

See commit comments.