UI still freezing when using async/await
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Using async and await does not automatically make the UI responsive. In JavaScript, the UI still freezes whenever the main thread is busy doing synchronous work, even if that work happens inside an async function.
Why async and await Are Not Magic
await only pauses until a promise settles. It does not move CPU-heavy code to another thread.
This function is asynchronous:
While the network request is pending, the browser can keep rendering the UI. That part is good.
But this function still blocks the UI:
Even though the function is marked async, the loop is still synchronous CPU work on the main thread. The browser cannot paint or handle user input until that loop finishes.
Identify the Real Cause
UI freezing usually comes from one of these:
- CPU-heavy loops
- too much DOM work in one turn
- synchronous parsing or transformation of large data
- serial
awaitusage that stretches user-perceived latency
The first category is the most common misunderstanding. async helps with waiting. It does not help with heavy computation unless you explicitly restructure that computation.
Break Work into Chunks
If the job can stay on the main thread, split it into smaller pieces so the browser can breathe between them.
This yields control back to the event loop periodically, which lets rendering and input handling continue.
It is not the same as true background execution, but it can make a dramatic difference in responsiveness.
Use Web Workers for Real CPU Work
If the work is genuinely heavy, the better fix is to move it off the main thread entirely.
Main thread:
Worker:
This is the right model when the problem is computation, not waiting.
Avoid Unnecessary Sequential await
Sometimes the UI feels frozen because work is serialized unnecessarily:
If the requests are independent, run them together:
This does not solve main-thread CPU blocking, but it does reduce wasted waiting time and can make the interface feel much snappier.
DOM Work Can Also Freeze the UI
Even without heavy calculations, a huge burst of DOM creation or layout-triggering updates can lock the UI for noticeable time. In that case, reduce reflows, batch updates, or virtualize long lists rather than focusing only on the async syntax.
Common Pitfalls
- Assuming
asyncmeans "runs on another thread". In JavaScript, it usually does not. - Putting CPU-intensive loops inside an
asyncfunction and expecting the UI to stay smooth. - Using
awaitinside loops when the tasks could run concurrently. - Forgetting that large DOM updates can freeze the UI even without network calls.
- Using zero-delay timers as a universal fix when the real answer should be a Web Worker.
Summary
- '
asyncandawaithelp with waiting on promises, not with heavy synchronous computation.' - The UI freezes when the main thread is busy, regardless of whether the function is marked
async. - Break long work into chunks if it must stay on the main thread.
- Use Web Workers for real CPU-heavy processing.
- Also watch for sequential awaits and expensive DOM updates, because both can make the interface feel stuck.
Related reading
- UIPopovercontroller dealloc reached while popover is still visible
- UIScrollView pauses NSTimer until scrolling finishes
- Unable to create new native thread error - but very few threads are in use
- Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint
- Undefined reference to pthread_create in Linux
- Understanding async in perl on specific example
- Unable to load script from assets index.android.bundle on windows
- Uncaught Error Invariant Violation Element type is invalid expected a string (for built-in components) or a class/function but got object

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.