I'd bet using setTimeout with a 0ms delay every loop wouldn't slow the example down significantly, and would have the desired effect of making the UI responsive.
Edit: close. https://html.spec.whatwg.org/multipage/webappapis.html#timer...
"Timers can be nested; after five such nested timers, however, the interval is forced to be at least four milliseconds."