Replace for-of loop based on performance metrics. Consider using RxJS to easily offload work using a scheduler. Maybe even consider a web worker.