Debugging Web Performance / Module 02

Module 2: Reading a Performance Trace

Read a Chrome performance trace from start to end: tasks, long tasks, the flame chart, self time, frames and Insights, on a real slow tap.

Maya set the laptop to the phone profile, pressed Record in the Performance panel, and tapped one seat. The recording showed one wide block on the main thread, labeled “Task”, and nothing she could read inside it. Leo looked over her shoulder.

“What’s that block?” he asked.

“Everything the phone did after the tap,” Maya said. “I need to read what’s inside it.”

Maya, Leo and TinyTickets are invented, and so are the numbers in their story.

This module teaches you to read a performance trace from start to end. In Module 1 you measured that a tap on the seat map is slow. Here you’ll open that tap, find the function and the source line that make it slow, and learn which parts of the trace to trust.

After this module, you can:

  • record a trace of a page load and of one tap in the phone profile, and say how the recording itself changes the numbers
  • follow a long task in the flame chart from the input event down to the function and the source line
  • use self time and total time in the Bottom-up and Call tree tabs to name where the time went
  • connect a trace to the field numbers through the Interactions track, dropped frames, Insights and live metrics
  • label your own code in the trace with performance.measure(), and record the same trace on a real Android phone

One tap, one block nobody could read

The field data from Module 1 still stands. On phones, at the 75th percentile, the seat map has INP 1,200 ms, LCP 4.8 s and CLS 0.25. Buyers wrote that the map “froze” when they tapped a seat.

In Module 1’s lab run, on the phone profile (412 × 823, Slow 4G, 6x CPU), one tap took 768 ms to the next frame. Its handlers ran for 373 ms inside a 463 ms task. Module 1 drew that task as one box, because the event entries it used can’t see inside a task. But a trace can.

A trace is a recording of what the browser did over a period of time. It holds every task on every thread, every network request and every frame, each with a start time and a duration. The Performance panel in Chrome DevTools records traces and draws them.

Pause and predict. The click handler changes one seat and then calls render(), which writes to all 60,000 seat elements. When you open the 463 ms task, what share of it do you expect to be the handler’s JavaScript? What else could the browser do in the rest of the time? Write down a percentage before you read on.

Record a performance trace of the tap

The recordings in this module were made with the lab app from Module 1, plus two lines this module adds later. But you can follow along with Module 1’s code as it is.

Set up the recording

Open Chrome in an Incognito window, so extensions don’t add their own work to the trace (DevTools tutorial). Start the lab server, open http://localhost:8080/seats.html and open DevTools.

In the Performance panel, before you record anything, you see live metrics: the LCP, CLS and INP of the page in this tab, measured by Chrome as you use the page (Performance panel reference). Tap a seat now, and the INP value and an entry in the Interactions log appear. Live metrics tell you that a tap was slow, but they keep no tasks, so they can’t tell you why.

Open the capture settings (the gear icon) and set the phone profile from Module 1: CPU “6x slowdown”, Network “Slow 4G”. Set the device toolbar to 412 × 823 with a touch device type, and check “Disable cache” in the Network panel. Turn on Screenshots.

The panel has two ways to record:

  • Record and reload loads the page from the start, records the load, and stops a few seconds after the load ends. Use it for LCP and everything before the first tap.
  • Record records until you press Stop. Use it for an interaction: load the page first, start recording, tap, then stop.

For the tap, load the page, scroll to the map, press Record, tap one blue seat, wait a second for the orange seat to appear, and press Stop.

What the recording costs

A recording slows the page it records. Chrome writes an event for every task, and in these runs it sampled the JavaScript call stack about every half millisecond. On this laptop, in the phone profile, six taps without recording took 816 to 1,016 ms, and three taps while recording took 1,040 to 1,160 ms.

The numbers also drift from day to day. Module 1’s tap took 768 ms on the same laptop and profile. So never compare a recorded number with an unrecorded one, and record the same thing three times before you trust a shape. The shape repeated in every run here, but the numbers didn’t.

The recordings behind this module were made with headless Chrome 157 through the DevTools Protocol, with trace categories close to the ones the Performance panel records. They were then read with the DevTools trace engine, the code behind the Performance panel and its Insights. Your recording in the panel will look the same in shape, with different numbers.

Rule: Compare the shape of three recordings, not the number from one.

How the main thread spends its time

The block Maya saw is a task. To read it, you’ll need four ideas: how a task blocks frames, why 50 ms is the line, how the flame chart is drawn, and its two times.

Tasks run to the end, and frames wait

The page’s main thread runs one task at a time: parse some HTML, run a script, handle an input event, fire a timer. A task runs to its end; nothing else on the main thread can start until it finishes. In DevTools, each one is a bar labeled Task at the top of the Main track.

After a task changes the DOM, the browser must update what’s on screen. That rendering work also runs on the main thread, as a series of steps. Figure 1 shows the steps the seat map trace names; Module 6 explains each one.

one task                        rendering steps on the main thread   screen
[input event -> your handlers] -> Recalculate style -> Layout
                               -> Pre-paint -> Paint -> Layerize
                               -> Commit  ----------------------->  frame

Recalculate style  which CSS rules apply to each changed element
Layout             where each element goes and how big it is
Pre-paint, Paint   record what to draw, element by element
Layerize, Commit   group the drawing into layers, hand them to the compositor

Figure 1: a change becomes a frame only after the task and every rendering step finish.

A frame is one picture the browser sends to the screen. A 60 Hz screen asks for one every 16.7 ms; a 120 Hz screen every 8.3 ms. A dropped frame is a moment when the screen was ready for a new picture and the browser had none, because the main thread was still busy.

Why 50 ms is the long-task line

A long task is a task that runs longer than 50 ms. DevTools marks it with a red triangle in the corner and fills the part after 50 ms with red stripes (web.dev). The DevTools source code uses exactly that test: a warning when the duration is over 50 ms.

The number comes from the RAIL model, which asked for a visible response to input within 100 ms. If no task is longer than 50 ms, input that arrives during a task waits at most 50 ms, which leaves 50 ms to handle it (web.dev, RAIL). Figure 2 shows that budget.

time (ms)    0         50        100
             |         |         |
main thread  [task, 50][ handle ]
tap            ^ arrives at 10 ms and waits for the task to end
               |-----------------|
               from tap to answer: under 100 ms

Figure 2: a 50 ms limit on every task leaves room to answer any input within 100 ms.

The same 50 ms is in the Long Tasks API, which lets a page observe its own long tasks. On 2026-10-20, the W3C published that specification as a Discontinued Draft, no longer maintained (W3C). But the API still works in Chrome 157, and DevTools still draws the 50 ms line. The web.dev RAIL page now points to the Core Web Vitals for setting goals, but nothing has replaced 50 ms as the long-task line in DevTools.

The flame chart draws the call stack over time

A flame chart is a chart with time from left to right and the call stack from top to bottom. Each bar is one call, and the bars under it are what it called (Performance panel reference). A wider bar took longer. The Main track of the Performance panel is a flame chart of the main thread.

The bars come from two sources:

  • Trace events that Chrome writes at the start and end of its own work: Task, Event: click, Function call, Recalculate style, Layout, Paint. Their start and end times are recorded, not estimated.
  • Samples of the JavaScript call stack, taken at a fixed interval. In the tap recording, the median gap between samples was 0.41 ms. So a function that runs for less than one interval can be missing, and many short calls in a row can look like one long call.

DevTools gives each script its own color, and keeps a fixed color for some categories: darker yellow for scripting and purple for rendering, across recordings (reference).

Total time and self time

Two numbers describe each bar. Total time is the time spent in an activity and everything it called. Self time is the time spent in the activity itself, not counting its children (reference, “The Call tree tab”).

A function with a large total time and a small self time only calls the slow code. A function with a large self time is where the time went. The walkthrough below uses both on the tap.

Find the cause of the slow tap in the trace

The steps below follow one recording of the tap, with Module 1’s code. Figure 3 is the Performance panel with the parts this walkthrough uses.

+--------------------------------------------------------------------+
| Timeline overview: CPU and NET charts, screenshots                 |
+--------------+-----------------------------------------------------+
| Sidebar:     | Tracks:  Network                                    |
|  Insights,   |          Frames                                     |
|  Annotations |          Interactions                               |
|              |          Timings                                    |
|              |          Main  (the flame chart of the main thread) |
+--------------+-----------------------------------------------------+
| Tabs: Summary | Bottom-up | Call tree | Event log                  |
+--------------------------------------------------------------------+

Figure 3: the overview finds the busy part, the tracks show what happened, and the tabs count it.

  1. Find the interaction. The Interactions track has one bar for the tap: 1,161 ms, with a red triangle because it’s over 200 ms. Its whiskers split it into the three parts Module 1 named. Input delay was 157 ms, processing 587 ms and presentation delay 417 ms.

  2. Find the tasks under it. In the Main track, below the interaction, are two long tasks: 737 ms, then 369 ms. Each has the red triangle and red stripes after its first 50 ms. A third long task, 79 ms, sits at the very start of the recording. It’s the profiler starting up (CpuProfiler::StartProfiling), not the page, so a long task in the first instant of a recording can belong to the recorder.

Pause and predict. The handler and render() are JavaScript. The second task, 369 ms, starts after all the JavaScript ended. What could the main thread spend 369 ms on after the code finished?

Answer

Drawing the change. render() changed the class of every seat element, so every seat must be painted again. The second task is Paint (275 ms), Layerize (71 ms) and Commit (17 ms). Your code isn’t in that task at all, but it caused it.

  1. Open the first task. Click it and zoom in (scroll on the track, or press W). Figure 4 is the flame chart of the 737 ms task.
  0       100     200     300     400     500     600     700 ms
  |       |       |       |       |       |       |       |
  [== Task, 737 ms ==========================================]
  [h][h] [== Event: click, 587 ms =====================][RLP]
          [== Function call  seats.js:35, 583 ms ======]
            [== render  seats.js:19, 546 ms ==========]
            || ||| || ||| || ||| || ||| || ||| || ||| |
      ^ red stripes from 50 ms to the end of the task

  [h] = Hit tests (three, 67 ms)
  [RLP] = Recalculate style, Layout, Pre-paint (57 ms)
  || = many short setAttribute calls under render

Figure 4: the task is the click handler, and the handler is render().

Read it from the top down. The task starts with three Hit test bars, 67 ms in total, while the browser works out which of the 60,000 seats is under the finger. Then Event: click runs the listener, a Function call at seats.js:35, which calls render. After the JavaScript, the same task runs Recalculate style, Layout and Pre-paint for 57 ms.

Most of the input delay of 157 ms is the 66 ms before this task started plus these hit tests. Finding the target among 60,000 elements is slow on a CPU slowed down 6 times.

  1. Count it in Bottom-up. With the task selected, open the Bottom-up tab. Bottom-up is a table of activities sorted by self time, with every call of the same function added together (reference). It answers “in which function did the time go?” Figure 5 shows the rows for the JavaScript in this task.
Activity Self time Total time
render (seats.js:19) 280.0 ms 545.6 ms
setAttribute 265.6 ms 265.6 ms
the click listener (seats.js:35) 26.6 ms 572.2 ms
Garbage collection 11.6 ms 11.6 ms

Figure 5: render() and the setAttribute calls it makes hold 546 of the 583 ms of JavaScript.

The listener has the largest total time and almost no self time. It only calls render(). Its own 27 ms is most likely elements.indexOf(event.target), a search through 60,000 elements. render() has 280 ms of self time in its loop and string building, and its setAttribute calls add 266 ms more.

Expand a row in Bottom-up to see who called it. setAttribute expands to render, so you’ll know which code to change even though the time is inside a browser function.

Pause and predict. Compare your guess from the start of the module. What share of the 737 ms task was the handler’s JavaScript?

Answer

583 of 737 ms, about 79%. The rest was 67 ms of hit testing and 57 ms of rendering steps, plus a few small events. And the next task, 369 ms of painting, was also caused by render(). Counting both tasks, the JavaScript is about half of the main thread’s work for this tap.

  1. Check the other view in Call tree. The Call tree tab shows the same time grouped from the top: the activities that started work, with what they called nested below. Here it reads Event: click > the listener > render > setAttribute. Use Call tree when you ask “which event caused the work?”, and Bottom-up when you ask “which function did it?”. The Event log tab lists the same activities in time order.

  2. Go to the line. Click render in Bottom-up. The Summary tab links to seats.js:19; the link opens the Sources panel at that line. That’s the function Module 5 changes.

  3. Look at the frames. The Frames track shows each frame: green when presented in time, yellow when partly presented, red when dropped (reference). In this trace, Chrome’s frame reporter marked 63 frames as dropped between the tap and the first frame with the orange seat. That frame started 1,155 ms after the tap.

  4. Read the Insights. The Insights tab in the sidebar lists checks that DevTools runs on the trace, each with the events it found highlighted when you hover it (Insights). For this tap recording, the trace engine marked one insight as failed: INP breakdown, with the three parts from step 1. The other checks, from Forced reflow to Optimize DOM size, passed. An insight points you to a metric and a part of the trace, but the flame chart and Bottom-up find the line.

Figure 6 puts the whole tap on the main-thread timeline, the figure this course draws in every module. The second task, which Module 1’s figure couldn’t separate from the wait for the frame, is marked NEW.

time (ms)     0         200       400       600       800       1,000
              |         |         |         |         |         |         |
tap           v
main thread      [========== task, 737 ms ===========][= task, 369 ms ==]  NEW
inside           [hit][=== click handlers, 587 ===][s][ paint, 275 ][l+c]
50 ms line       [=]
frames        x x x x x x x x x x x x x x x x x x x x x x x x x x x x x |
INP parts     |-------|----------------------------|--------------------|
              157     587 processing               417 presentation

hit = Hit test   s = Recalculate style, Layout, Pre-paint
l+c = Layerize, Commit
x = dropped frames (63)   | = the frame that shows the orange seat (1,161 ms)

Figure 6: one tap makes two long tasks, and 63 frames drop before the seat turns orange.

Rule: Follow a long task from the top bar down to the bar with the most self time, then expand it to find the code you own.

The same reading on the page load

Module 1 left a question open: on the phone profile, the image finished downloading, and yet LCP came 0.6 s later. A Record and reload recording answers it.

Pause and predict. The seat map’s script builds 60,000 elements. How many long tasks do you expect during the load, and which one will be the longest?

In this recording, the load had seven tasks over 50 ms. The two largest:

  • Evaluate script seats.js, 1,199 ms. Bottom-up for it shows render with 708 ms of self time and the script’s top level with 447 ms, which includes 195 ms of Parse HTML for the innerHTML string.
  • A rendering task of 2,744 ms that runs no JavaScript at all: Recalculate style 465 ms, Layout 1,601 ms, Pre-paint 174 ms, Paint 421 ms and Layerize 69 ms. It’s the first rendering of 60,000 grid items.

Figure 7 is the page-load timeline from Module 1, from this recording, with a main-thread row added.

time (s)     0         1         2         3         4         5         6
             |         |         |         |         |         |         |
seats.html   ======
styles.css         ======
analytics.js       ======
seats.js           =======
stadium.jpg        ==============================================
main thread               [=== JS ===][====== rendering, 2.74 s =][P]  NEW
                   ^ TTFB 0.56 s
                          ^ FCP 1.32 s (the h1)
                                          LCP 5.55 s (stadium.jpg) ^

JS = seats.js, 1.20 s   P = a task that paints the image, 0.23 s
(vitals.js and the web-vitals library also load; they are left out here)

Figure 7: from 1.3 s to 5.3 s the main thread is busy, so the image can’t be painted when it arrives.

The LCP breakdown insight splits this run’s LCP of 5,550 ms into four parts: time to first byte 564 ms, resource load delay 70 ms, resource load duration 4,522 ms and element render delay 393 ms. The 393 ms answers Module 1’s question. The image’s bytes were there, but the main thread was finishing the 2,744 ms rendering task, and then needed a 231 ms task to paint the image. Module 3 works on the 4,522 ms.

The other insights on the load agree with Module 1. Layout shift culprits names an unsized image, stadium.jpg. Optimize DOM size lists the largest updates: a layout of 60,008 objects (1,601 ms) and a style recalculation of 60,000 elements (465 ms).

One surprise is in the Long Tasks API. In the same run, a longtask observer in the page reported three long tasks, including the 1,198 ms script task, but not the 2,744 ms rendering task. Chrome’s documentation says rendering often happens in separate tasks that the Long Tasks API may not count together with the script that caused them (Chrome for Developers). But the trace shows all of them, and Module 5 covers an API that sees rendering too.

In Firefox and Safari

Chrome is this course’s lab browser, but buyers on iPhones run Safari’s engine, so you’ll sometimes record there.

  • Firefox. The Firefox Profiler is Firefox’s performance recorder, opened from a toolbar button or the DevTools panel (docs). Its names differ from Chrome’s. Its Flame Graph adds up all calls of a function, with no time axis. Its Stack Chart has time from left to right, like Chrome’s flame chart (panel tour). It shows performance.mark() and performance.measure() in its Marker Chart.
  • Safari. Web Inspector’s Timelines tab records JavaScript and events, layout and rendering, and network requests; its Frames view plots each frame’s duration against 30 and 60 FPS lines (WebKit). Since Safari 26.2 (December 2025), it shows LCP entries (WebKit blog). To record an iPhone, you’ll need a Mac, and Web Inspector turned on in the phone’s Safari settings (WebKit).
  • CLS. LCP and INP are measured in all three engines. CLS is measured only in Chromium browsers, so Firefox and Safari don’t report CLS as zero; they don’t report it at all (web.dev, 2025-12-17).

What changed recently

The Performance panel has changed more since 2024 than in the years before. If an older article sends you to a panel that doesn’t exist, this list is why.

  • Chrome 129 (September 2024): live metrics, with field data from CrUX next to your own numbers (release notes).
  • Chrome 131 (November 2024): the Insights and Annotations tabs in the sidebar, and a new Layout shifts track (release notes).
  • Chrome 132 (January 2025): the separate “Performance insights” panel was removed; its features moved into live metrics, Insights and the tracks (release notes).
  • Chrome 142 (October 2025): saved traces are compressed with gzip by default (Save trace). The same version lets you chat with Gemini about a whole trace (release notes). That AI assistance is off by default, needs a signed-in Google Account, and sends trace data to Google (data use). Everything in this module works without it.
  • Chrome 143 (December 2025): a saved trace can include the page’s scripts, styles and source maps (release notes).
  • Chrome 153 (2026-09-08): Chrome now ships a new version every two weeks, and the DevTools release notes became one post per month (Chrome blog).
  • 2026-10-20: the Long Tasks API became a W3C Discontinued Draft (W3C).
  • Chrome 157 and 158 (November 2026): DevTools parses large traces about 26% faster (release notes).

The fix: give the block a name

This module changes no seat map behavior; render() gets faster in Modules 5 and 6. So the fix is to the trace. In Figure 4, the important bar was called “Function call seats.js:35”, and you had to read the stack to learn it was render(). In a minified production bundle, that bar would have a one-letter name.

User Timing is a web API for adding your own named points and spans to the browser’s performance timeline. performance.mark() records a point, and performance.measure() a span between two points (MDN). DevTools draws them in the Timings track, above the Main track.

Change public/seats.js in two places. Time the map’s construction, and time every call of render():

const SEAT_COUNT = 60000;
const map = document.getElementById('map');
const status = document.getElementById('status');

// About 6 in 10 seats are already sold. The pattern is fixed, so every run is the same.
const seats = Array.from({ length: SEAT_COUNT }, (_, i) => ({
  id: i,
  row: Math.floor(i / 200) + 1,
  number: (i % 200) + 1,
  price: i < 20000 ? 95 : 60,
  sold: (i * 7919) % 10 < 6,
}));
const picked = new Set();

const buildStart = performance.now();
map.innerHTML = '<span class="seat"></span>'.repeat(SEAT_COUNT);
const elements = [...map.children];
performance.measure('build-map', { start: buildStart });

// Brings every seat element up to date with the seat list.
function render() {
  const start = performance.now();
  let free = 0;
  for (const seat of seats) {
    const state = seat.sold ? 'sold' : picked.has(seat.id) ? 'picked' : 'free';
    const label = `Row ${seat.row}, seat ${seat.number}, $${seat.price}, ${state}`;
    const element = elements[seat.id];
    element.className = `seat ${state}`;
    element.title = label;
    element.setAttribute('aria-label', label);
    element.setAttribute('aria-disabled', seat.sold);
    element.setAttribute('aria-pressed', state === 'picked');
    if (state === 'free') free++;
  }
  status.textContent = `${free} seats free, ${picked.size} picked`;
  performance.measure('render', { start });
}

map.addEventListener('click', (event) => {
  const id = elements.indexOf(event.target);
  if (id === -1 || seats[id].sold) return;
  picked.has(id) ? picked.delete(id) : picked.add(id);
  render();
});

render();

The four new lines are buildStart, the build-map measure, start and the render measure. performance.measure(name, { start }) without an end ends the span now, so each measure covers exactly the code above it.

Record the tap again. Figure 8 shows the Timings track before and after the change, from one recording each.

Before (Module 1 code), tap task 737 ms:
Timings      (empty)
Main         [== Task, 737 ms ========================================]
                 [== Event: click, 587 ms ===================]
                   [== Function call  seats.js:35, 583 ms ===]

After (with performance.measure), tap task 552 ms:
Timings          [== render, 435.1 ms ==============]          NEW
Main         [== Task, 552 ms ============================]
                 [== Event: click, 438 ms ===========]
                 [== Function call  seats.js:39, 436 ms ==]

Figure 8: the render measure lines up with the function call, so the block now has a name.

The render measure was 435.1 ms, and the function call that contains it 436.4 ms. In the load recording, build-map (411.9 ms) and the first render (766.4 ms) sat inside the 1,223 ms script task. The same names appear in the trace of anyone who records this page, and in the console:

performance.getEntriesByType('measure').map((e) => `${e.name} ${Math.round(e.duration)} ms`);

Before and after

The question for any measurement code is whether it slows the thing it measures. These runs alternated between the two versions of seats.js, without recording, on the phone profile, six taps each:

Version Tap, from input to next frame
Before: Module 1 code 816 to 1,016 ms
After: with the two measures 776 to 896 ms

The ranges overlap, so these runs can’t show any cost from the two calls; the noise between runs is far larger. But one recording of each changed the trace from an unnamed function call to a render bar of 435.1 ms.

What it costs

  • Memory. Each measure stays in the page’s performance timeline until you call performance.clearMeasures() (MDN). After one tap, the lab page held two render entries. A page that measures every frame for an hour should clear them.
  • Names are public. Anyone who records your production page sees your measure names. So don’t put buyer data in them, or in the detail field.
  • Only what you label. A measure shows the span you chose. The second task, 369 ms of painting, runs after render() returns, so the render measure doesn’t include it.

Other ways to label the trace

Option What it shows Its cost When to choose it
performance.measure() A named span in the Timings track; your own code can read it too An entry kept per call Spans you also want to read in code or in the Firefox Profiler
console.timeStamp() with start, end and track name (Chrome 134) A span on your own track, only in the trace The track arguments work only in Chrome; code cannot read it Many labels per second, where you want almost no cost when nobody records (extensibility API)
detail.devtools on a measure (Chrome 128) The measure on a custom track with your own color and tooltip More code; turn on “Show custom tracks” A framework or library that wants its own track

React 19.2 and Angular 20 draw their own tracks with console.timeStamp() (release notes, Chrome 144).

Check it on a real phone, then in the field

A throttled laptop isn’t a phone (Module 1, Figure 3). Remote debugging is running DevTools on your computer against Chrome on an Android phone connected by USB, so the trace records the phone’s own CPU, GPU and memory (remote debugging). Figure 9 shows the setup.

(You) --> [laptop: Chrome, chrome://inspect, DevTools]
             |   USB cable
             v
          [Android phone: Chrome, seats.html]
             | port forwarding: the phone's localhost:8080 and :8081
             v   go over the cable to the laptop
          [lab server on the laptop: 8080, 8081]

Figure 9: the phone runs the page, and the laptop records it.

  1. On the phone, turn on Developer options and USB debugging.
  2. On the laptop, open chrome://inspect#devices and check Discover USB devices. Connect the phone and accept the prompt on it.
  3. Click Port forwarding and add 8080 to localhost:8080 and 8081 to localhost:8081. The phone can then open http://localhost:8080/seats.html from the laptop’s server, without Wi-Fi (local server).
  4. Open the page in Chrome on the phone, click Inspect next to its tab on the laptop, and record in the Performance panel as before, with no CPU throttling.

You’ll need an Android phone, ideally a slow one, a data cable, and developer options turned on. The version of Chrome on the phone decides which DevTools version opens. The screencast of the phone’s screen lowers its frame rate, so turn it off while you record (remote debugging). An iPhone needs Safari’s Web Inspector on a Mac instead.

Maya borrowed Nina’s older Android phone and recorded one tap on it. The shape matched the laptop’s: one task with the render bar inside, then a long paint task.

Then she checked the field, where every page load with a tap has sent its INP and its three parts to /vitals since Module 1. That week, buyers browsing next month’s shows sent 212 INP lines from phones on the seat map. In 190 of them, processing duration was the largest part, and every line named DIV#map.onclick in seats.js. The trace’s cause was the buyers’ cause.

Online tools for this step

Both tools below read trace files, and a trace file isn’t anonymous. It carries details of the machine that recorded it, such as the number of CPU cores, the operating system and the Chrome version. With Include resource content checked, it also holds your page’s HTML, CSS and JavaScript (Save trace). So never upload a trace of a private or internal page to a public service.

The DevTools Performance panel as a trace viewer. To save, use the download button, then Save trace. Resource content and source maps are off by default, and gzip is on. To open a trace, use the upload button or drop the file on the panel.

  • Data: lab, from whoever recorded it. Free, and nothing leaves your machine.
  • Limit: you share a file, not a link. For a link, trace.cafe uploads a Chrome trace and gives a URL that expires after one year. It’s a third-party site, not a Google service, and its page shows no privacy policy.
  • Size: the load recording behind this module, made through the protocol, was 12.3 MB as JSON and 0.84 MB with gzip; the tap recording was 0.77 MB and 0.07 MB.
  • When to use it: almost always; it’s the same view you recorded in, with Insights and annotations. Before you share a trace, add annotations. Double-click a bar to label it, or Shift-drag over a range to label the range (annotations). Saved traces keep them.

The Firefox Profiler opens Firefox recordings and other profile formats in the browser.

  • Data: lab. Free and open source. A profile stays on your computer until you upload it. After upload, anybody with the link can read it, and the link also stores your current view and filters (getting started). You can remove some information before uploading, and delete an upload later from the same browser.
  • Limit: it records Firefox, not Chrome. Its source has an importer for Chrome trace files. It has none of Chrome’s Insights, live metrics or Layout shifts track.
  • When DevTools is better: for anything about Chrome’s numbers, CLS, or Chrome’s rendering steps. The Firefox Profiler is the choice when the slow browser is Firefox, or when you need to share a profile as a link with a view already set.

Check yourself

Debugging scenario

The waiting page has a button, “Show my place”, which lists the buyers ahead of you. At 9:58, buyers say the button “does nothing for a while”. On the phone profile, live metrics show INP 420 ms after one tap.

Maya records the tap. The Interactions track shows one click of 420 ms. In the Main track:

  • A 95 ms task starts 40 ms before the tap. Its top bar under the task is Timer Fired, and below that pollQueue (waiting.js:70), which a setInterval calls.
  • A 300 ms task starts right after it: Event: click (296 ms), then Function call waiting.js:40.
  • A 20 ms task with Paint follows, and the frame with the list appears at 420 ms.

Call tree for the 300 ms task:

Activity Total time Self time
Event: click 296 ms 2 ms
showPlace (waiting.js:40) 294 ms 4 ms
renderList (waiting.js:12) 290 ms 30 ms
toLocaleString 240 ms 240 ms
Garbage collection 20 ms 20 ms

Where do the input delay and the processing time come from, and which line of code should Maya change first?

Hint 1

The tap arrived 40 ms after a 95 ms task started. When could the click handler begin?

Hint 2

In Bottom-up, the row with the most self time is a browser function. Expand it: who calls it?

Answer

The timer task was running when the tap arrived, and a task runs to its end. It ended 55 ms after the tap, so the handler started about 60 ms after the tap. That’s the input delay.

The click task is the processing time, 296 ms. Bottom-up puts toLocaleString first, with 240 ms of self time. It’s a browser function, and when you expand it, its caller is renderList, which calls it once per row.

renderList at waiting.js:12 is the code to change, so that it formats fewer numbers. showPlace has the most total time but only 4 ms of self time; it only calls renderList.

The rest is presentation delay. 420 ms minus 60 ms of input delay and 296 ms of processing leaves 64 ms, covered by the paint task and the frame.

Review questions

  1. You record a tap and get 1,160 ms; without recording it took 900 ms. Which number do you compare with your next recording, and why?
  2. Why does DevTools mark a 51 ms task as long and a 49 ms task not, and where does the 50 ms come from?
  3. A function has 500 ms of total time and 3 ms of self time. Where did its time go, and which tab shows you where?
  4. Live metrics show a tap with an INP over 1 second. Which track do you open first in the recording, and why did frames keep dropping after the tap’s JavaScript ended at 744 ms?
  5. You add performance.measure('render', { start }) at the end of render(). Where does it appear in the trace, what does it not cover, and what should you turn off when you record the same tap on an Android phone?
Answers
  1. The next recording’s number. Recording slows the page, so compare recorded with recorded, and record three times to check the shape.
  2. DevTools marks a task when it runs longer than 50 ms. The number comes from RAIL: if no task runs over 50 ms, input waits at most 50 ms and still gets an answer within 100 ms.
  3. In the functions it called. Bottom-up sorts by self time and shows where the time went; Call tree shows the path from this function to that code.
  4. The Interactions track: its bar for the tap splits INP into input delay, processing and presentation delay, and the INP breakdown insight points to it. The frames kept dropping because the main thread was running the rendering steps that render() caused. Recalculate style, Layout and Pre-paint ran at the end of the first task, then Paint, Layerize and Commit in a second task.
  5. In the Timings track, as a render bar lined up with the function call. It doesn’t cover the painting that comes after render() returns. On the phone, turn off the screencast, because it lowers the phone’s frame rate.

Lab: record, read and label the slow tap

Time: about 15 minutes. You’ll need the lab app from Module 1, Chrome and Node.js. The finished code for this module is in the course repository, folder module-02/.

  1. Start the server with node server.js. Open an Incognito window, open http://localhost:8080/seats.html, and open DevTools. In the Performance panel, set CPU “6x slowdown” and Network “Slow 4G”, check “Disable cache” in the Network panel, and set the device toolbar to 412 × 823 with touch.
  2. Click Record and reload. Before you look, predict how many tasks over 50 ms the load will have. Then count the red triangles in the Main track.
  3. Find the longest task during the load, and the task that runs Evaluate script for seats.js. Write down the total time of each, and the top three rows in Bottom-up for the script task.
  4. Scroll to the map. Click Record, tap one blue seat, wait a second, and click Stop. Find the interaction in the Interactions track, and write down its input delay, processing duration and presentation delay. Follow the first long task under it down to the source line.
  5. Add the four lines of performance.measure() from the fix section to public/seats.js. Reload, record the tap again, and find the render bar in the Timings track. Compare its duration with the Function call bar under it.
  6. Paste this into the Console after the page loads. It prints your measures and every long task the Long Tasks API saw. Compare its long tasks with the red triangles from step 2.
const ms = (n) => `${Math.round(n)} ms`;
new PerformanceObserver((list) => {
  for (const e of list.getEntries()) console.log(e.entryType, e.name, 'at', ms(e.startTime), 'for', ms(e.duration));
}).observe({ type: 'longtask', buffered: true });
for (const e of performance.getEntriesByType('measure')) console.log('measure', e.name, 'at', ms(e.startTime), 'for', ms(e.duration));
  1. Label the long task “render: all 60,000 seats” with a double-click, then save the trace with gzip and without resource content. Open the file again with the upload button and check that the label is there.
Results from one run

These come from headless Chrome 157 on a 2019 laptop (Intel Core i7-9750H) through the DevTools Protocol, one run each. Your numbers will differ, but the shape shouldn’t.

  • Step 2: seven tasks over 50 ms. The longest was a 2,744 ms rendering task with no JavaScript (Layout 1,601 ms); the script task was 1,199 ms.
  • Step 3: the longest task was the rendering task above. For the script task, render had 708 ms of self time and the script’s top level 447 ms, including 195 ms of Parse HTML.
  • Step 4: the tap took 1,161 ms. Input delay 157 ms, processing 587 ms, presentation delay 417 ms. The first task (737 ms) leads through Event: click and the listener at seats.js:35 to render at seats.js:19.
  • Step 5: the render measure was 435.1 ms, and the function call under it 436.4 ms.
  • Step 6, the console output after one load:
measure build-map at 1432 ms for 289 ms
measure render at 1722 ms for 751 ms
longtask self at 1367 ms for 1108 ms
longtask self at 5981 ms for 72 ms
longtask self at 6101 ms for 150 ms

The API reported three long tasks. The trace in step 2 had seven, because the API doesn’t report the tasks that only rendered, such as the 2.7 s first rendering of the grid.

Stretch: repeat step 4 on an Android phone through chrome://inspect, with port forwarding and no CPU throttling. Compare the length of the render bar with your laptop’s.

Cheat sheet

Reading a performance trace
  1. Live metrics say that it is slow; a recording says why
  2. Record: "Record and reload" for the load, "Record" for one tap
  3. Recording slows the page: compare recordings with recordings, three times
  4. Red triangle: task > 50 ms, interaction > 200 ms
  5. Flame chart: time left to right, callers above callees
  6. Bottom-up: most self time first; expand a row to find its caller
  7. Call tree: which event started the work
  8. Work after your function returns (paint) is still caused by it
  9. performance.measure() names your code in the Timings track

Figure 10 is the whole module in one picture: the order in which to read a trace.

[metric: INP or LCP, from live metrics or the field]
   |                                  Insights point to the
   v                                  metric and the events
[Interactions or Timings track]  <--  worth checking first
   |  which span?
   v
[long task in Main]   red stripes after 50 ms
   |
   v
[flame chart]         read from the top bar down
   |
   v
[Bottom-up]           most self time first, then expand to its caller
   |
   v
[source line]         the code you own

Figure 10: start from the metric, find its span, then go down the stack to the line.

Next, in Module 3, Maya takes the 4.5 seconds of image download from the LCP breakdown and follows them into the network waterfall of the show page.

Sources