The standard advice for a page that freezes during heavy JavaScript is to break the work into chunks and "yield to the browser" between them. That advice is right, but it hides a choice. There are at least five common ways to yield, and they don't give the browser the same thing.
Some let it handle a click. Some let it paint a frame. Some do both, at a price. And the usual metric, long tasks over 50 ms, can't tell them apart, because all of them end the long task.
I wanted numbers, so I ran one job five ways in three engines and counted what the user would actually see: frames painted, the longest gap between them, and how long a click waited for the screen to respond.
The test
The job. 600,000 CSV rows of made-up expenses (37 MB of text, built in the page from a seeded generator). The loop splits each line, adds the amount to a per-category total and counts the words in a note column. In one go it takes about 0.45 to 0.55 seconds, depending on the engine. That's long enough to be a visible freeze, and typical of what a browser-only CSV or log tool does with a big file.
Five ways to yield:
const mc = new MessageChannel(); const q = []; mc.port1.onmessage = () => q.shift()(); const YIELD = { setTimeout: () => new Promise(r => setTimeout(r, 0)), schedulerYield: () => scheduler.yield(), messageChannel: () => new Promise(r => { q.push(r); mc.port2.postMessage(0); }), rafThenTimeout: () => new Promise(r => requestAnimationFrame(() => setTimeout(r, 0))), postTaskBackground: () => scheduler.postTask(() => {}, { priority: 'background' }), }; rafThenTimeout is the "wait for the next frame, then continue right after it" pattern. postTask with background priority asks the scheduler to run the continuation after more important work.
When to yield. Two policies: every 20,000 rows (30 yields), and a time budget of 10 ms (yield whenever the current slice has run for more than 10 ms, about 50 to 60 yields). The time budget is the better habit, because rows don't all cost the same.
for (let i = 1; i < lines.length; i++) { processRow(lines[i]); if (performance.now() - sliceStart > budgetMs) { bar.style.width = (100 * i / lines.length) + '%'; // a progress bar the user should see move await yieldFn(); sliceStart = performance.now(); } } What I measured. A requestAnimationFrame loop records the gap between frames, from the start of the job until 150 ms after it ends. Chrome also reports long tasks. For input, Playwright sends a real mouse click to a button, waits 50 ms, and repeats while the job runs; the page records how long each click took to reach the next frame.
Browsers. Google Chrome 156 (headless, new mode), Playwright's Firefox 153.0 build and Playwright's WebKit 26.5 build, on an 8-core Linux machine. Three runs per setup. Ranges below are the lowest and highest of the three runs. The WebKit build is not Safari: same engine, different app around it.
Finding 1: every method ended the long tasks; not every method painted
Here is the 10 ms budget in all three engines, with no user input during the job:
| Method (10 ms budget) | Chrome: frames | Chrome: longest gap | Firefox: frames | Firefox: longest gap | WebKit: frames | WebKit: longest gap |
|---|---|---|---|---|---|---|
| No yielding (one go) | 11 | 500–533 ms | 10–11 | 429–459 ms | 10–11 | 517–532 ms |
setTimeout(0) | 54–57 | 33–100 ms | 44–45 | 35–44 ms | 57–60 | 31–32 ms |
scheduler.yield() | 16 | 100–117 ms | 18–21 | 66–83 ms | not supported | not supported |
MessageChannel | 44–46 | 17–33 ms | 18–19 | 67–84 ms | 42–43 | 31–32 ms |
rAF, then setTimeout | 63–69 | 17–33 ms | 48–49 | 38–51 ms | 56–58 | 30–32 ms |
postTask background | 44–47 | 17–33 ms | 17–20 | 67–84 ms | not supported | not supported |
Frames counted from the job's start until 150 ms after it ended (the job took 0.45 to 1 s, see Finding 4). At 60 Hz a smooth page paints a frame every 16.7 ms.
Apart from a single 117 ms task in one setTimeout run (a one-off that didn't repeat), Chrome reported no long task over 53 ms for any yielding method in this table, and none at all in the three scheduler.yield() runs. By the usual metric, all of them "fixed" the page. But in Chrome, scheduler.yield() painted only 16 frames while the job ran for about 0.6 seconds, and the longest gap was 100 to 117 ms. The progress bar moved in a few big jumps instead of smoothly. With a 40 ms budget, the gaps reached 133 ms.
The reason is the point of scheduler.yield(). Its continuation is meant to run before other queued work, so a yielded task doesn't lose its place in line. If nothing else is waiting, the job picks up again almost at once, and the browser gets few chances to paint. The gaps clustered at 100 to 133 ms in every Chrome run. That looks like a cap on how long Chrome lets rendering wait, but I didn't confirm it in Chrome's source.
Firefox showed the same thing for three methods: scheduler.yield(), MessageChannel and postTask with background priority all painted only 17 to 21 frames, with gaps of 66 to 84 ms. setTimeout and the rAF pattern painted 44 to 49.
The every-20,000-rows policy told the same story: scheduler.yield() painted 15 to 16 frames in Chrome and 20 to 21 in Firefox, while setTimeout painted 42 to 50 and 39 to 40.
Finding 2: with input, Chrome's scheduler.yield() did what it promises
Then I added the clicks. This changed Chrome's picture a lot:
| Chrome 156, 10 ms budget | Frames, no input | Frames, clicking | Longest click-to-frame wait |
|---|---|---|---|
| No yielding | 11 | 11 | 445–471 ms |
setTimeout(0) | 54–57 | 54–60 | 34–40 ms |
scheduler.yield() | 16 | 46 | 33–34 ms |
MessageChannel | 44–46 | 43–47 | 15–42 ms |
rAF, then setTimeout | 63–69 | 63–66 | 16–17 ms |
With clicks arriving, scheduler.yield() painted 46 frames instead of 16, and every click reached the screen within 34 ms. Without yielding, a click waited up to 471 ms. So for what it was designed for (keeping the page responsive to the user while a task runs), scheduler.yield() worked well in Chrome. When the user does something, Chrome handles it and paints. When the user only watches a progress bar, it paints much less often.
I'm not reporting Firefox's click numbers. In Playwright's Firefox, the synthetic clicks couldn't be delivered while the main thread was busy, so their timestamps only start when the page is free again, and the waits look shorter than they were.
Finding 3: the WebKit build has no scheduler at all
'scheduler' in window was false in the WebKit 26.5 build, so neither scheduler.yield() nor scheduler.postTask() exist there. Chrome 156 and Firefox 153 had both. Calling scheduler.yield() without a check would throw in WebKit, so every use needs a fallback:
const yieldToMain = globalThis.scheduler?.yield ? () => scheduler.yield() : () => new Promise(r => setTimeout(r, 0)); The MDN page for scheduler.yield() has the current support table. Check it rather than trusting a version number in an article, including this one.
In WebKit, all three methods that exist painted well: 42 to 60 frames, with gaps of 30 to 32 ms on the 10 ms budget.
Finding 4: the frames have a price
Painting more frames means giving the browser more time, and the job takes longer. Total time for the same 600,000 rows, 10 ms budget, no input:
| Method | Chrome | Firefox | WebKit |
|---|---|---|---|
| No yielding | 527–551 ms | 441–475 ms | 517–532 ms |
scheduler.yield() | 584–630 ms | 452–459 ms | n/a |
MessageChannel | 607–624 ms | 456–462 ms | 528–542 ms |
setTimeout(0) | 770–880 ms | 621–622 ms | 763–824 ms |
rAF, then setTimeout | 890–995 ms | 693–703 ms | 753–789 ms |
The rAF pattern painted the most frames everywhere and cost the most: in Chrome the job took 60 to 90% longer than in one go. Plain setTimeout(0) was also slow, and part of that is likely the minimum delay of about 4 ms that browsers apply to deeply nested timers, paid at each of 50-plus yields. scheduler.yield() and MessageChannel were nearly free, and that is exactly why they paint so little: they give the time back to your job.
A middle ground: yield cheaply, but wait for a frame when one is overdue
If you want the speed of scheduler.yield() and a progress bar that moves, you can combine them: use the cheap yield normally, and wait for a real frame only when none has been painted for a while.
let lastFrameAt = performance.now(); (function tick() { lastFrameAt = performance.now(); requestAnimationFrame(tick); })(); const yieldSmart = () => (performance.now() - lastFrameAt > 32) ? new Promise(r => requestAnimationFrame(() => setTimeout(r, 0))) // a frame is overdue: let it paint : yieldToMain(); // otherwise: cheap yield With no input, on the 10 ms budget:
| Hybrid | Frames | Longest gap | Total time |
|---|---|---|---|
| Chrome 156 | 24–25 (was 16 with scheduler.yield()) | 50–67 ms | 565–592 ms |
| Firefox 153 | 26–27 (was 18–21) | 34–72 ms | 481–540 ms |
WebKit 26.5 build (uses setTimeout) | 57–65 | 32–48 ms | 755–901 ms |
It is a compromise, not magic. It roughly halved the longest gaps in Chrome and kept the job about as fast as scheduler.yield() alone, but it didn't reach the smoothness of the rAF pattern. With clicks, in Chrome, it painted 44 to 48 frames and every click reached the screen within 38 ms.
Which one to use
- The user is clicking, typing or scrolling while the work runs:
scheduler.yield()with asetTimeoutfallback. It was the fastest way to stay responsive in Chrome, and it doesn't lose the job's place in line. - The user is watching progress: make sure a frame gets painted at least every 30 to 50 ms. Either use the rAF pattern and accept the slower job, or use the hybrid above.
- Don't count on
MessageChannelor backgroundpostTaskto paint. In Firefox they starved rendering as much asscheduler.yield()did. - Use a time budget, not a row count. Rows aren't equally expensive, and a budget keeps slices short on slow devices.
- If the work doesn't touch the DOM, move it off the main thread. A Web Worker avoids the whole trade-off: the page paints at full speed and the job runs at full speed, at the cost of moving data across.
Check your own page in 10 lines
Long-task counts won't show this problem, so measure frames directly. Paste this into the console, run your heavy action, then call report():
let gaps = [], last = performance.now(), on = true; (function tick(t) { if (on) { gaps.push(t - last); last = t; requestAnimationFrame(tick); } })(performance.now()); function report() { on = false; const sorted = gaps.slice().sort((a, b) => b - a); console.log({ frames: gaps.length, longestGapMs: Math.round(sorted[0]), over50ms: gaps.filter(g => g > 50).length }); } If the longest gap is over 100 ms while a progress bar is supposed to move, the user sees a stall, whatever the long-task panel says. Google's guide to optimizing long tasks explains the yielding patterns in more depth.
This matters most for tools that process files in the browser, where the whole point is that the data stays on the user's device and the work happens on their CPU. FindUtils has many of them, such as the CSV Viewer and the CSV to JSON converter, and the same trade-offs apply to any page like that.
What this doesn't show
- Real displays and real hands. Chrome ran headless and the clicks were synthetic. Frame timing on a real 60 Hz or 120 Hz screen, and with real input, will differ in detail.
- Safari and mobile. The WebKit build isn't Safari, and an 8-core desktop is not a mid-range phone. On a slower CPU, the same job takes longer and every gap gets longer.
- Other kinds of work. A loop of string parsing yields cleanly. Work that can't be split (one huge
JSON.parse, decoding an image) blocks no matter how you yield. - Firefox input delay. I couldn't measure it reliably with Playwright's Firefox (see Finding 2).
The takeaway is simple: "I added yields" isn't the end of the job. Measure what the user sees, because one popular way to yield turned out to be very good at handling clicks and quite bad at moving a progress bar.
Building a dashboard or admin panel that has to stay smooth with large data? The team behind FindUtils takes on freelance work on Upwork, including a fast React front end for your web app, dashboard or admin panel.

