Skip to content

Lesson 3 of 14 · 25m

The Profiling Workflow That Finds the Real Bottleneck

From a bad field number to a specific line of code: reproduce the failing segment, read the waterfall and the trace, verify against field p75.

Every team has an engineer who knows why the site is slow — usually whatever they complained about in the last code review: the big date library, the framework, the ORM. Sometimes they're right. More often the trace shows something nobody suspected: a tag manager firing synchronously in the head, a 4 MB hero video poster, a JSON.parse of a 1.2 MB inline state blob. This workflow exists so opinions don't get to skip the evidence.

The loop

Measure-reproduce-profile-fix-verify loop

1. FIELD      which metric, which route, which segment is failing at p75?
2. REPRODUCE  match that segment in the lab (device, network, cache state)
3. PROFILE    capture a trace + waterfall; name the sub-part that dominates
4. HYPOTHESIZE one cause, one change, one predicted effect
5. FIX        smallest change that tests the hypothesis
6. VERIFY     lab first (did the sub-part shrink?), then field (did p75 move?)

Step 2 is the one people skip: profile on a fast laptop on a warm cache and you'll optimize a page that was already fine for you.

Reproduce the slow segment

If the failing segment is mid-range Android on 4G, emulate it. In DevTools' Performance panel set CPU throttling to 4×–6× (calibrate against a real device — recent DevTools ships a calibrated "low-tier mobile" preset) and network to "Slow 4G". Use an Incognito window so extensions don't contaminate the trace. Decide cold load vs. warm load up front and stay consistent.

For repeatable lab runs:

npx lighthouse https://shop.northwindgear.com/product/trail-runner-3 \
  --only-categories=performance \
  --form-factor=mobile --throttling-method=devtools \
  --output=json --output=html --output-path=./reports/pdp \
  --chrome-flags="--headless=new"

Run it three to five times and take the median — single Lighthouse runs vary 10–20% on a shared machine. WebPageTest earns its keep for real-device, real-location runs and for the filmstrip, which ends every argument about what the user actually saw at 2 s.

Reading the evidence

The network waterfall answers LCP questions. Find the LCP resource: when was it requested relative to the HTML? A long gap is resource load delay — the browser didn't know it existed. A long bar is load duration — too big, or served from a slow origin. Requests ahead of it at equal priority mean it's competing.

The Performance trace answers INP and render-delay questions:

  • Long tasks (red corner, >50 ms) on the Main track — expand one, sort Bottom-Up by self time to find the function actually burning CPU.
  • Purple "Recalculate Style" / "Layout" blocks right after JS — forced synchronous layout from reading geometry after writing styles.
  • The Interactions track splits each interaction into input delay, processing, and presentation delay.
// Instrument your own code so it shows in the Timings track
performance.mark("filters:apply:start");
applyFilters(state);
performance.mark("filters:apply:end");
performance.measure("filters:apply", "filters:apply:start", "filters:apply:end");
console.log(performance.getEntriesByName("filters:apply")[0].duration.toFixed(1), "ms");

Verify in the field, not just the lab

A lab improvement is a hypothesis about the field. Ship behind a flag or to a percentage, then compare p75 for exposed vs. control in your RUM, segmented exactly the way you found the problem. If the lab got faster and the field didn't move, your reproduction didn't match reality — go back to step 2.

Field notes

  • One change per experiment. Three fixes and a better number teaches you nothing about which one mattered.
  • Bottom-Up answers "what's expensive"; the flame chart answers "why was it called." Use both, in that order.
  • Third-party scripts appear attributed to their origin in the trace. List them; they're frequently half your main-thread time.
  • Export traces (they save as JSON) and attach them to the ticket. A trace in the PR description ends more arguments than any benchmark.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.