Course contentsShow
← Web Development
Lesson 2057 of 2,98238. JavaScript Performance in the BrowserFree lesson

Identifying Main-Thread Blocking

Using DevTools Performance panel to identify long tasks that block the main thread for over 50ms.

Identifying Main-Thread Blocking

You'll learn how to use Chrome DevTools' Performance panel to spot long tasks that freeze your UI for over 50ms.

What is Main-Thread Blocking?

Remember from earlier lessons that the main thread handles JavaScript execution, rendering, and user interactions. When a single task runs for more than 50ms, it blocks everything else—your page becomes unresponsive, animations stutter, and clicks don't register. These are called long tasks, and they're performance killers.

Think of the main thread like a single-lane road. When one slow truck (a long task) blocks the lane, all the cars behind it (rendering updates, user clicks) have to wait, no matter how urgent they are.

Using DevTools Performance Panel to Find Blocking

The Performance panel is your diagnostic tool for identifying these bottlenecks:

  1. Open Chrome DevTools → Performance tab
  2. Click Record (or Cmd+E / Ctrl+E)
  3. Interact with your page for a few seconds
  4. Stop recording

In the flame chart, look for:

  • Long yellow bars in the Main section (JavaScript execution)
  • Red triangles in the corner of tasks—these mark long tasks over 50ms
  • Gray sections labeled "Task" that stretch horizontally

Click on any suspicious task to see:

  • Its exact duration (look for >50ms)
  • Which function caused it
  • The call stack showing where it originated

The panel shows you exactly what is blocking and for how long, giving you concrete targets for optimization using techniques like setTimeout, code splitting, or Web Workers.

Key Takeaway: The Performance panel's red triangles and task duration measurements reveal main-thread blocking tasks over 50ms, showing you precisely which code needs optimization to keep your UI responsive.