Fix and prove it

Make a change, re-run, compare, disciplined performance work.

7 minmedium

Finding the bottleneck is the easy half. The hard half is the discipline after it: one change, re-measured the same way, kept or reverted on the number rather than on how clever it felt.

The loop

1. Measure run the test, record the number, say which stage
2. Form a hypothesis "p95 is pool wait, because DB CPU is high and ours is not"
3. Change ONE thing the smallest edit that tests the hypothesis
4. Measure again same test, same data, same machine, same stage
5. Keep or revert on the number, not on the reasoning

Step three is where most performance work goes wrong. Two changes at once gives you one number and no attribution, and the usual outcome is that both get kept: the one that helped, and the one that made things slightly worse and is now load bearing for no reason.

Same test, same data, same machine

A comparison is only a comparison if everything else held still. The things that move without anybody deciding to move them:

  • The data. A load test writes rows. The second run starts with a bigger table than the first, so a "15% regression" can be nothing but the table growing. Reset the database between runs, or use read only journeys for comparisons.
  • The machine. A laptop that was idle for run one and compiling for run two produces a number about the compiler. Close the other work, and watch the load generator's own CPU.
  • The stage. Comparing a p95 over the whole run against a p95 over the hold is comparing two different questions. Pick one and write it down.
  • Warmth. First run after a restart has cold caches and an empty pool. Discard it, or always discard it, but be consistent.

Run the before measurement twice before you change anything. The gap between those two runs is your noise floor, and no improvement smaller than that gap is an improvement. People skip this and then celebrate 4% on a benchmark that varies by 9%.

k6 says what moved. Pulse says why

k6 is outside the process. It can tell you p95 went from 40ms to 310ms, and it has no way to tell you which function those 310ms were in. Pulse is inside the process, and the two are meant to be read together.

perf/README.md
# The run registers itself in Pulse, so the slow p95 arrives with the
# profile of what was burning during it.
set -a; source .env; set +a # PULSE_USERNAME / PULSE_PASSWORD
k6 run perf/load.js

That is grit generate perf, which writes a k6 script that calls Pulse at the start and end of the run. Three things come out of it that k6 cannot measure:

  • Traffic per route before, during and after, from the API's own rollups rather than from k6's view of its own requests.
  • Queries per request, and N+1 findings, in each window. An N+1 that is invisible at one request a second is exactly what falls over at 500 VUs.
  • A CPU profile captured over the run, so you get the flame graph of the slow window rather than of an idle process afterwards.

Write the result down, including the failures

notes.md
2026-10-29 average-load, 100 VUs, hold stage, RESOURCE=products
before (x2): p95 311ms, 298ms noise floor ~13ms
change: Preload("Category") on the list query
after: p95 104ms queries/request 21 -> 2
kept
2026-10-29 same test
change: DB_MAX_OPEN_CONNS 25 -> 50
after: p95 101ms within noise
reverted, no effect at this concurrency

The second entry is the one worth keeping. A change that did nothing is a fact about your system, and without the note somebody tries it again in three months, including you.

Try it

One. Run the average load test twice without changing anything. The difference between the two p95s is your noise floor. Write it down.

Two. Make one change you believe will help, from last lesson's shortlist. Re-run. Record whether the change is larger than the noise floor.

Three. Revert it and run again. Confirm the number goes back.

Quick check

You change three things at once and p95 improves by 40%. What do you know?

Spot a typo? Have an idea?

Help us improve this lesson. One click opens a GitHub issue with the lesson URL pre-filled, suggest clearer wording, report a bug, or request more depth. The course keeps improving thanks to learners like you.

Suggest an improvement on GitHub