Performance Hands-On 20 - Maximum call stack size exceeded

Performance Tools: Call Stack Analysis

Exercise 1: Understanding Call Stack Limits

The browser's Performance panel can help analyze stack overflows and recursive function performance.

  1. Open DevTools (F12 or right-click and select "Inspect")
  2. Go to the Performance tab
  3. Click the record button (⚫)
  4. Click the button below to trigger a recursive loop
  5. Stop recording once the error appears
  6. Analyze the call stack in the flame chart

Exercise 2: Optimizing Recursion

Let's see how setTimeout affects our recursive function in the Performance panel:

  1. Start a new recording in the Performance tab
  2. Click the button below to run the delayed version
  3. Observe how the call stack appears different in the flame chart
  4. Notice how setTimeout creates separate "tasks" instead of a continuous stack

Exercise 3: CPU Profiling

The Performance panel can also show CPU usage patterns:

  1. Start a new recording with "CPU profile" checked
  2. Click the button below to run a CPU-intensive operation
  3. Look at the CPU chart in the timeline view
  4. Explore the "Bottom-Up" and "Call Tree" tabs to find performance bottlenecks

Performance Panel Tips

Hint: When analyzing performance, look for "long tasks" (colored red in the timeline) that may be causing jank. Also, compare the call stack height between the regular recursion and setTimeout versions to understand how event loop and task queuing work in JavaScript.