Basic

What is actually slow

Performance work starts with a measurement, not a guess. The browser spends time in three places: fetching bytes, parsing and painting, and running your code. Each has a different unit and a different fix, and only a measurement tells you which one you are in.

What you will see

A dated line with both numbers. The next release diffs against it.

About 1 min of reading

Try It

Get one honest number for one page

1

Open the network panel

open the page with the browser tools open and clear the cache

Before you run it, say out loud what it will print. Then open the answer.

What it prints
A waterfall of requests with start, wait, and finish times.
2

Read the critical request

sort the requests by finish time and take the last one before the text was readable

Before you run it, say out loud what it will print. Then open the answer.

What it prints
That request is the one whose removal would move the interaction time.
3

Throttle and re-measure

set the network to Slow Fast and the CPU to 4x throttle, then reload

Before you run it, say out loud what it will print. Then open the answer.

What it prints
A much larger number. That is the number a real user on a bad connection sees.
4

Write both numbers down

printf '%s ms-to-readable: %s bytes: %s\n' "$(date +%F)" "$MS" "$BYTES" | tee -a docs/perf-log.md

Before you run it, say out loud what it will print. Then open the answer.

What it prints
A dated line with both numbers. The next release diffs against it.
Do not record a number taken from a warm cache. The first honest number is the cold one, and it is the one that matters.

Data Flow

Request to a painted pixel
1 Request starts and DNS plus connect run
↓
2 Bytes arrive over the network
↓
3 HTML parses and resources are discovered
↓
4 Layout and paint run
↓
5 Your scripts run against that state
Why this works
The unit you should report

Milliseconds to the interaction, plus the bytes that made it. Two numbers per page is enough to decide what to fix and enough for someone else to reproduce.

Where guesses go wrong

The classic wrong guess is optimizing the biggest file when the slowness is a blocking request. Size and count are different axes and only measurement separates them.

Examples

The three budgets

Bytes over the wire cost time proportional to the network. Parse and paint cost time proportional to the document. Your JavaScript costs time proportional to what it does. A 2 MB image and a 2 MB JSON file are not the same problem.

Measure the field, not the machine

A local server on an idle machine hides the network and the CPU throttle. Throttle the connection and the CPU in the tools before you believe any number.

One number per page

Record the time to the thing a user interacts with, not the time to load. For a reading page that is when the text is readable; for a game it is when the first frame draws.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
Request count versus file size
Request count versus file size →