Following the optimize long tasks article, here's a playground to try the browser's native scheduling API.
This example renders a list of 100,000 div elements and x4 CPU throttling.
for (let i = 0; i < 100_000; i++) {
// with scheduling
scheduler.postTask(() => render(i))
// without scheduling
// render(i)
}
function render(i) {
const item = document.createElement('div')
item.innerText = `Item ${i}`
item.style.display = 'inline-block'
document.body.appendChild(item)
}
Results in a single huge 8.35s user-blocking task (FCP 11.16s).
Results in many non-blocking tasks (FCP 3.74s).