Trace a performance problem to its cause
Separates the slow thing from the thing you noticed.
Something is slow. Help me find out what, before I optimise the wrong thing. Symptom: [WHAT IS SLOW, AND HOW SLOW] What I have measured so far: [PROFILE OUTPUT, TIMINGS, OR "NOTHING YET"] Stack: [LANGUAGE, FRAMEWORK, DATABASE] Work through it: 1. What are the plausible causes, ranked by how often they turn out to be the answer in a system like this? 2. For each, the cheapest measurement that would confirm or eliminate it. 3. Which measurement should I take first — the one that eliminates the most possibilities. If I have given you no measurements, say so and give me the first one to take. Do not suggest optimisations yet. An optimisation applied to the wrong layer is worse than none, because it adds complexity and moves nothing.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
Symptom: The orders list page in our admin takes 6 to 8 seconds to load. In spring it took under 1 second. The orders table has grown from about 40,000 rows to 310,000 since then.
What I have measured so far: The browser's network tab only. The HTML response takes 6.4 seconds to arrive, and the scripts and images after it add 0.3 seconds. Nothing on the server yet.
Stack: Python, Django, PostgreSQL.
Example output
Your one measurement already rules something out. Of about 6.7 seconds, 6.4 pass before the HTML arrives, so the browser, the scripts and the images are not the cause. The time goes on the server.
1. Plausible causes, most likely first
- A query that scans the whole orders table, because it filters or sorts on a column with no index. It fits the history: its cost grows with the table.
- The pagination count. A paginated list counts every matching row on each load, and that count slows as the table grows.
- A query per row. The page fetches each order's customer or items one at a time. Common in Django, but its cost follows the page size and not the table size, so it explains a slow page better than a page that got slower.
- Python, not the database. The view loads far more rows than it shows and trims them in memory.
2. The cheapest measurement for each
| Cause | Measurement |
|---|---|
| Full scan | Run the list query under EXPLAIN ANALYZE and look for a sequential scan on orders |
| Count | Time the paginator's COUNT(*) query on its own |
| Query per row | Count the queries for one page load. Hundreds means this one |
| Python | Subtract the total query time from 6.4 seconds. The rest is Python |
3. Take this one first. Log every query of one page load with its duration. Django keeps them in django.db.connection.queries when DEBUG is on, so do it on a copy of the production data. That one list sorts all four causes. One slow query points at 1 or 2, hundreds of fast ones at 3, and a small total at 4.
I have suggested no fix. An index added before that measurement would be a guess.
More Coding prompts
3 of the 7 other prompts filed under Coding.
Turn a README into something someone can follow
Rewrites project docs around what a newcomer actually gets stuck on.
Write tests for this function
Table-driven tests covering the boundaries, not just the happy path.
Write the tests that would have caught this
Turns a bug you just fixed into the regression test you should have had.
Coding tools and skills
3 of the 9 tools and 3 of the 7 skills filed under Coding, the same category as this prompt.
Continue
Open-source coding agent for VS Code, JetBrains and the CLI. Cursor acquired it, and the repository is read-only.
Cursor
An editor built around AI-assisted editing.
Devin Desktop
A full IDE with a command center for running local and cloud coding agents. It used to be called Windsurf.
Accessibility reviewer
Reviews a component against WCAG failures that automated tools miss.
Release notes writer
Writes release notes and a changelog from a commit range, leaving out the commits users never notice.
Test writer
Writes tests that fail for the right reason and refuse to test the framework.
Coding guides
3 of the 6 guides filed under Coding, the same category as this prompt.
Claude Code alternatives: agentic coding tools compared
What Claude Code needs from you today, which agents replace it in the terminal, in an editor, on your own models or in the cloud, and which of them read your SKILL.md files.
GitHub Copilot alternatives: AI coding assistants compared
What Copilot Free covers today, which tools on this index replace it in your editor, in the terminal, on your own models or across a large codebase, and the catch of each.
Cursor alternatives: AI code editors and agents compared
What Cursor's plans include today, which tools on this index replace it as an editor, an extension, a terminal agent or a browser builder, and the trade-off of each.