The neighbourhood head tallies the score cards on the main thread: in one go or cut up with setTimeout, scheduler.yield, requestAnimationFrame or await…
Why it matters
A page that feels heavy though it loads fast almost always has long tasks: buttons react late, scrolling stutters, typing lags. INP measures that delay on real users, Total Blocking Time in the lab. Cutting the work up and pausing is a fix you feel at once.
The key idea
The same work; all that changes is whether it pauses
Common mistakes
Using await and it still freezes?await on a settled Promise resumes as a microtask, before the event loop gets a turn: the loop stays one task. A real pause is await new Promise((r) => setTimeout(r)) or await scheduler.yield().
Already cut into pieces and still janky Every piece must stay under 50 ms on its own. Do not cut by a count of items; read performance.now() in the loop and pause once a piece nears the limit, because a slow device can be several times slower.
Pausing with requestAnimationFrame, why so slow?requestAnimationFrame waits for the next frame, so every piece costs a frame: a second of work can stretch to several, and stops altogether in a background tab. For work that draws nothing, use setTimeout or scheduler.yield().
Try it in this playground
In one go, then press Ask at the booth in the middle Your press waits until the task ends; the yellow line on the main thread’s lane is the delay.
Cut every 20 ms with setTimeout, press again Served between pieces, within milliseconds.
Try await Promise.resolve() Cut in the code, yet still one task and no frame.
Pause with requestAnimationFrame Compare its total time with its work.