Part of #116901. Besides the typical changes from past similar refactors, the loops are now multithreaded.