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
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?
Keep reading
Related articles from the SudoSecurity blog.
What is Vite? The Build Tool That Made Frontend Development Fast Again
Vite replaced Webpack for a lot of teams without much fanfare. Native ES modules, a dev server that starts in milliseconds, and a production build that doesn't require understanding 300 lines of config. Here's how it works and why the switch is worth it.
PHP API Performance: N+1 Queries, cURL, and Connection Pools
A PHP API case study: fixing an N+1 query, twenty serial cURL calls, missing connection pooling, and stats recalculated on every request with Redis caching.
Inside TypeScript 7: What a Year-Long Rewrite in Go Actually Bought Developers
A deep look at how Microsoft's Go-based TypeScript 7 compiler achieves its speed gains, and what the Visual Studio Code team's year-long migration reveals about adopting it safely.
Node.js vs Deno vs Bun: Picking the Right JavaScript Runtime in 2026
Three JavaScript runtimes. Three different philosophies on what the developer experience should feel like. Here's how they compare on performance, ecosystem, tooling, and the only decision that actually matters for production.