CS Fundamentals Trainer · JavaScript · Performance & Memory
A click handler runs a 400 ms computation on the main thread, which makes the page feel frozen. Which changes let the browser handle input…
A click handler runs a 400 ms computation on the main thread, which makes the page feel frozen. Which changes let the browser handle input and paint while the work is done?
- Marking the handler `async` without adding any `await` inside the loop
- Splitting the work into chunks and yielding between them with `setTimeout` (or `scheduler.yield()` where supported)
- Splitting the work into chunks scheduled with `queueMicrotask`
- Moving the computation into a Web Worker and posting the result back
- Running the whole computation inside one `requestAnimationFrame` callback
Difficulty: hard