Performance
Measure Where the Time Goes Before You Optimise Anything
Perceived speed is four hops: browser, server, database, cold start. Optimising the wrong one is free-looking work.
A page feels slow. An engineer immediately assumes the JavaScript bundle is too heavy, spends three days converting components to dynamic imports, reduces the bundle by 40kB, and deploys. The page is still slow.
Because the latency was never in the bundle. The latency was an unindexed database query taking 900ms before returning the initial HTML.
The four hops of web latency
Every request traverses four distinct boundaries, and each has its own order of magnitude:
- DNS & TLS: connecting to the server (50ms - 200ms).
- Time to First Byte (TTFB): the server computing the response (50ms - 2000ms).
- Network transit: downloading the bytes (10ms - 500ms).
- Browser parsing & rendering: evaluating JavaScript and painting the DOM (50ms - 1500ms).
Total load: 2,400ms
- TTFB (backend query): 1,850ms (77%)
- Download CSS/JS: 150ms (6%)
- React hydration: 400ms (17%)
Optimising React hydration addresses at most 17% of the latency.Optimising without profiling is just moving code around until you get tired.
The profiling protocol
Before opening a component file, run a single request through WebPageTest or Chrome DevTools Network tab with CPU throttling disabled. Look at the water fall: if the white bar (waiting for server) dwarfs the blue bar (content download), your frontend is fast and your backend is broken. Fix the bottleneck that actually owns the time.