toolhq.io

skills / code quality and testing

performance-triage

Find the actual bottleneck with a measurement before changing anything, then prove the fix with the same measurement.

SKILL.md

Save as .claude/skills/performance-triage/SKILL.md in a repository, or under ~/.claude/skills/performance-triage/SKILL.md to have it everywhere. The copy button takes the whole file, frontmatter included.

---
name: performance-triage
description: Find the real bottleneck with a profile or a trace, fix the largest contributor first, and prove the fix with the same measurement that found it. Use when asked to make something faster, investigate a slow page, endpoint, query or job, or confirm that an optimisation worked.
---

# Performance triage

Measure before you change anything. A guess about where the time goes is wrong
often enough that acting on one costs more than taking the profile.

## Define the target first

1. Name the metric precisely. "The page is slow" is not a metric. "The 95th
   percentile response time of the search endpoint" is.
2. Name the target and who set it. Without a target you cannot tell when to
   stop, and performance work with no stopping point never ends.
3. Record the baseline: the number, the command or tool that produced it, the
   data set and the machine. You will run exactly this again at the end.

If nobody can say what fast enough means, ask before measuring anything.

## Measure something that resembles production

- Use a production build. A development build carries extra checks, unminified
  code and disabled caches, so its profile points at costs users never pay.
- Use data at a realistic size. A query that is instant against fifty rows
  says nothing about five million.
- Decide whether you are measuring a cold start or a warm one, and keep that
  the same across every run.
- Run it several times. Report the median and the spread, not the best run.

## Find the bottleneck

Take a profile or a trace of the slow path and read it by total time.

1. Classify the time before reading any code. These three need different fixes
   and are routinely confused:
   - **Compute** — the processor is busy in your code. An algorithm or data
     structure problem.
   - **Waiting** — blocked on a network round trip, a database or a disk. The
     code is idle, so faster code will not help. Fewer calls, batched calls or
     parallel calls will.
   - **Render** — the data arrived on time and the screen is late. Layout,
     paint, too many nodes, or long work on the main thread.
2. Find the single largest contributor. If one item is 70 percent of the time,
   nothing else is worth touching yet.
3. Check how often it runs. Cost is time per call multiplied by call count.

The trap is optimising the ugliest code instead of the slowest path. A clumsy
nested loop that runs twice at startup costs nothing. A tidy helper that issues
one query per row, called for every row of a list, is the whole problem and
looks innocent in review.

## Fix one thing

1. Change the largest contributor only.
2. Run the baseline measurement again: same command, same data, same machine,
   same number of runs.
3. If the number did not move beyond the spread, revert. A change that does not
   help is complexity with no return.
4. Take a fresh profile. The bottleneck has moved, so the old profile no longer
   describes the system.
5. Stop when the target is met.

## What not to do

- **Do not optimise without a profile.** Intuition about hot paths is wrong
  more often than it is right.
- **Do not report a speed up from a single unrepeated run.** One run measures
  cache state and machine load as much as the code.
- **Do not bundle several optimisations into one change.** You will not know
  which one worked, or whether one of them made things worse.
- **Do not add a cache as the first move.** A cache hides the slow path, adds
  an invalidation problem, and leaves the first request as slow as before.
- **Do not trade correctness for speed** without saying so explicitly.

## Leave the measurement in place

A fix with no guard regresses within months. Leave behind whichever fits: a
benchmark in the repository, a budget checked in CI, or a dashboard panel with
an alert on the metric you defined at the start.

## Say how sure you are

- **Measured** — repeated runs before and after, same conditions, numbers given.
- **Inferred** — the profile points here but the fix is not yet measured.
- **Not measured** — a guess from reading code. Label it as one.

If you could only measure a development build or toy data, say that the result
may not carry over, and name what a proper measurement would need.

## Report back

1. The metric, the target and the baseline, with how each was measured.
2. Where the time went, by kind, with the numbers from the profile.
3. What changed, and the result after: median, spread and number of runs.
4. What now guards against a regression, and what you did not measure.

what it needs

Nothing. This skill is instructions only, so it works in any agent that reads SKILL.md with nothing installed and no account. Save the file and it is live in the next session.

the instructions, in full

Performance triage

Measure before you change anything. A guess about where the time goes is wrong often enough that acting on one costs more than taking the profile.

Define the target first

  1. Name the metric precisely. "The page is slow" is not a metric. "The 95th percentile response time of the search endpoint" is.
  2. Name the target and who set it. Without a target you cannot tell when to stop, and performance work with no stopping point never ends.
  3. Record the baseline: the number, the command or tool that produced it, the data set and the machine. You will run exactly this again at the end.

If nobody can say what fast enough means, ask before measuring anything.

Measure something that resembles production

Find the bottleneck

Take a profile or a trace of the slow path and read it by total time.

  1. Classify the time before reading any code. These three need different fixes and are routinely confused:
    • Compute — the processor is busy in your code. An algorithm or data structure problem.
    • Waiting — blocked on a network round trip, a database or a disk. The code is idle, so faster code will not help. Fewer calls, batched calls or parallel calls will.
    • Render — the data arrived on time and the screen is late. Layout, paint, too many nodes, or long work on the main thread.
  2. Find the single largest contributor. If one item is 70 percent of the time, nothing else is worth touching yet.
  3. Check how often it runs. Cost is time per call multiplied by call count.

The trap is optimising the ugliest code instead of the slowest path. A clumsy nested loop that runs twice at startup costs nothing. A tidy helper that issues one query per row, called for every row of a list, is the whole problem and looks innocent in review.

Fix one thing

  1. Change the largest contributor only.
  2. Run the baseline measurement again: same command, same data, same machine, same number of runs.
  3. If the number did not move beyond the spread, revert. A change that does not help is complexity with no return.
  4. Take a fresh profile. The bottleneck has moved, so the old profile no longer describes the system.
  5. Stop when the target is met.

What not to do

Leave the measurement in place

A fix with no guard regresses within months. Leave behind whichever fits: a benchmark in the repository, a budget checked in CI, or a dashboard panel with an alert on the metric you defined at the start.

Say how sure you are

If you could only measure a development build or toy data, say that the result may not carry over, and name what a proper measurement would need.

Report back

  1. The metric, the target and the baseline, with how each was measured.
  2. Where the time went, by kind, with the numbers from the profile.
  3. What changed, and the result after: median, spread and number of runs.
  4. What now guards against a regression, and what you did not measure.

credit

This skill covers ground first mapped by addyosmani/agent-skills, a widely used open collection of engineering skills. The instructions above are written from scratch for this library, in its own voice and with its own opinions, and nothing is copied. The thanks is for the idea.