The Scheduler API: Prioritising Work on the Main Thread
Every performance problem in the browser eventually traces back to the same crime: something blocked the main thread for too long. The user clicked a button. The browser wanted to run the click han...

Source: DEV Community
Every performance problem in the browser eventually traces back to the same crime: something blocked the main thread for too long. The user clicked a button. The browser wanted to run the click handler, repaint the changed pixel, and move on. But before it could, your application decided this was a great time to parse a 4 MB JSON payload, diff a 3,000-node virtual DOM, and synchronously compute analytics. The animation dropped frames. The button felt broken. The user noticed. We have spent years routing around this problem. Debouncing, throttling, Web Workers, requestIdleCallback, virtualizing long lists — all of them are, at their core, strategies to stop doing too much on the main thread at once. The Scheduler API takes a different angle. It doesn't tell you to do less work. It lets you tell the browser which work matters right now and which can wait — and it actually enforces that. Why The Old Solutions Fall Short Before reaching for anything new, it's worth being honest about the t