CoreMesh

Find Why Code Is Slow

Guessing at performance problems wastes time. This prompt asks for the likely bottlenecks in order, how to measure each one, and a fix only for the one you confirm.

Works with Claude, ChatGPT and Gemini4 fields

prompt.md · 497 charslive
This Python 3.12 + SQLite code is slow (about 9 seconds for 5,000 users). I need under 1 second.

```
for user in users:
    orders = db.execute('SELECT * FROM orders WHERE user_id=?', (user.id,)).fetchall()
```

1. List the likely bottlenecks, most likely first, with one sentence each.
2. For each, tell me how to measure it so I can confirm before changing code.
3. Then show the fix for the most likely one, and the trade-offs it brings.
Do not micro-optimize code that is not on the hot path.

Everything you type stays in your browser. Remove passwords, keys and personal data before pasting anything into an AI tool.

Why this prompt is written this way

  • Measure first. Asking how to confirm each bottleneck keeps you from rewriting the wrong part.
  • Real numbers. Giving the current time and the target lets the model judge whether a fix is big enough.
  • No micro-optimizing. Without that rule, models often polish loops that are not the problem.

Example answer

Illustrative and shortened, to show the shape of a good answer. Real answers vary by model.

1. N+1 queries: one SELECT per user (most likely).
2. Missing index on orders.user_id.
Measure: count queries per request; run EXPLAIN QUERY PLAN.
Fix: one query with WHERE user_id IN (...) or a JOIN, plus CREATE INDEX ON orders(user_id).

Tips

  • Measure before and after with the same data so you know the fix worked.
  • Mention the data size; the right fix for 1,000 rows differs from 10 million.

How to use it

  1. Replace the example values with your own. The prompt on the right updates as you type.
  2. Press Copy prompt and paste it into any AI chat, or open it straight in Claude or ChatGPT.
  3. Save it as prompt.md if you want to reuse it.
Claude ↗

New notes, no spam.

One post at a time, only when there's something worth reading. Follow in any feed reader.

Subscribe via RSS